【问题标题】:Problem with adding a custom field to existing view向现有视图添加自定义字段的问题
【发布时间】:2019-08-21 13:54:22
【问题描述】:

[![在此处输入图像描述][1]][1]我在向 odoo12 的销售订单视图添加新字段时遇到问题。我创建了一个新模块。我希望你能帮助我。 在我的视图表单的代码下方

<odoo>
    <record id="view_order_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml"></field>
                <field name="payment_term_id" position="after">
                        <field name="additional_note"/>
                </field>
</record>
</odoo>```

when i try to install the new module i have the following error:

File "src\lxml\etree.pyx", line 3557, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: record, line 3


  [1]: https://i.stack.imgur.com/e1DOw.png

【问题讨论】:

    标签: view module odoo


    【解决方案1】:

    问题出在&lt;field name="arch" type="xml"&gt;&lt;/field&gt; 行:&lt;field&gt; 标记已关闭,而您的additional_note 字段在其外部声明。

    试试这个代码:

    <odoo>
    
        <record id="view_order_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <!-- Leave the 'arch' field open -->
            <field name="arch" type="xml">
                <!-- Put your custom field and its position inside the 'arch' field.
                     Use 'xpath' tag to create a more precise positioning -->
                <xpath expr="//group/group/field[@name='payment_term_id']" position="after">
                    <field name="additional_note"/>
                </xpath>
            <!-- Now, close the 'arch' field -->
            </field>
        </record>
    
    </odoo>
    

    【讨论】:

      【解决方案2】:

      视图定义不正确,可以参考account_analytic_view

      视图定义应该是(根据提供的链接):

      <odoo>
          <record id="view_order_form_inherit" model="ir.ui.view">
              <field name="name">sale.order.form</field>
              <field name="model">sale.order</field>
              <field name="inherit_id" ref="sale.view_order_form"/>
              <field name="arch" type="xml">
                  <data>
                      <field name="payment_term_id" position="after">
                          <field name="additional_note"/>
                      </field>
                  </data>
              </field>
          </record>
      </odoo>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-09
        • 1970-01-01
        • 2013-04-07
        • 1970-01-01
        • 2014-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多