【问题标题】:I can't replace a field after I have inherited a view继承视图后无法替换字段
【发布时间】:2013-04-22 21:25:38
【问题描述】:

我需要在我的项目模块中使用任务功能(我继承了“project.project”)。 我继承了这样的“project.task”:

class task(osv.osv):
  _name = "project.task"
  _description = "Task"
  _date_name = "date_start"
  _inherit = 'project.task'
  _columns={
          'my_project_id': fields.many2one('project.my.project', 'Project'),
          }

  task()

现在我需要将任务创建表单中的 project_id 字段替换为“my_project_id”。我这样做了:

<record id="view_task_form2_inherited" model="ir.ui.view">
        <field name="name">project.task.form</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="project.view_task_form2"/>
        <field eval="2" name="priority"/>
        <field name="arch" type="xml">
            <field name="project_id" position="replace">
                <field name="my_project_id"/>
            </field>

   </field>
</record>

它给了我这个错误:Uncaught Error: NameError: name 'project_id' is not defined。

请注意,如果我使用 position="before" 或 "after",“my_project_id”字段会正确添加(在“project_id”字段之前/之后)。

【问题讨论】:

    标签: openerp


    【解决方案1】:

    使用 xpath 试试

    <xpath expr="//field[@name='project_id']" position="replace">
    

    希望它会起作用。

    【讨论】:

      【解决方案2】:

      替换前检查源模型视图

      使用xpath替换

      在 expr 中使用在 xml 中定义字段的确切路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多