【问题标题】:How to inherit particular view in our own module? ODOO如何在我们自己的模块中继承特定的视图? ODOO
【发布时间】:2016-01-12 00:48:51
【问题描述】:

大家早上好,我想从 ODOO 视图中继承一些视图。这样我就可以使用我自己的模块。谁能解释一下,有什么可能的方法吗?

提前致谢!

【问题讨论】:

    标签: python xml views openerp odoo


    【解决方案1】:

    查看继承

    Odoo 提供了视图继承,而不是修改现有视图(通过覆盖它们),其中子“扩展”视图应用在根视图之上,并且可以从其父视图添加或删除内容。

    扩展视图使用 inherit_id 字段引用其父视图,而不是单个视图,它的拱字段由任意数量的 xpath 元素组成,选择和更改其父视图的内容:

    <!-- improved idea categories list -->
    <record id="idea_category_list2" model="ir.ui.view">
        <field name="name">id.category.list2</field>
        <field name="model">idea.category</field>
        <field name="inherit_id" ref="id_category_list"/>
        <field name="arch" type="xml">
            <!-- find field description and add the field
                 idea_ids after it -->
            <xpath expr="//field[@name='description']" position="after">
              <field name="idea_ids" string="Number of ideas"/>
            </xpath>
        </field>
    </record>
    

    表达式 在父视图中选择单个元素的 XPath 表达式。如果不匹配任何元素或匹配多个元素,则引发错误 位置

    Operation to apply to the matched element:
    
    inside
        appends xpath's body at the end of the matched element
    replace
        replaces the matched element by the xpath's body
    before
        inserts the xpath's body as a sibling before the matched element
    after
        inserts the xpaths's body as a sibling after the matched element
    attributes
        alters the attributes of the matched element using special attribute elements in the xpath's body
    

    提示

    匹配单个元素时,可以直接在要查找的元素上设置position属性。下面的两个继承都会给出相同的结果。

    <xpath expr="//field[@name='description']" position="after">
        <field name="idea_ids" />
    </xpath>
    
    <field name="description" position="after">
        <field name="idea_ids" />
    </field>
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      这里是我如何在我的新模块中继承和使用现有视图。我想继承购买视图,所以在我的模块中我继承了 purchase.order 对象

      class purchase_order(osv.osv):
      _inherit="purchase.order"
      

      //你可以像往常一样在这里添加任何你想要的字段

      我继承了下面这样的视图

      <record id="purchase_order_advance_invoice_inherit_form" model="ir.ui.view">
      <field name="name">purchase.order.advance.invoice.inherit.form</field>
      <field name="model">purchase.order</field>
      <field name="inherit_id" **ref="purchase.purchase_order_form"**/>
      

      //这里是我要继承的视图,你可以完成rest标签

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-04
        • 1970-01-01
        • 1970-01-01
        • 2021-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多