【问题标题】:Inherited xpath not showing - Odoo v8继承的 xpath 未显示 - Odoo v8
【发布时间】:2017-06-09 04:03:28
【问题描述】:

我正在继承视图mrp_workorder_variation.mrp_production_workcenter_form_view_inherit_2并添加一个新页面,但它没有显示,我不知道为什么,这是我的代码:

  <record id="mrp_production_workcenter_form_view_inherit_3" model="ir.ui.view">
        <field name="name">MRP Production Work Book Block</field>
        <field name="model">book.block.code</field>
        <field name="inherit_id" ref="mrp_workorder_variation.mrp_production_workcenter_form_view_inherit_2"/>
        <field name="arch" type="xml">

            <xpath expr="//page[@string='Input/Output Products']" position="after">
                <page string="Book Block">                                                         
                    <group>                                                                         
                        <group string="Book Block">                                               
                            <field name="name"/>
                            <field name="description"/>
                        </group>                                                                    
                    </group>                                                   
                </page>  
            </xpath>

        </field>
    </record>

这是我继承的原始视图:

 <record id="mrp_production_workcenter_form_view_inherit_2" model="ir.ui.view">
        <field name="name">MRP Production Workcenter Line</field>
        <field name="model">mrp.production.workcenter.line</field>
        <field name="inherit_id" ref="mrp_operations.mrp_production_workcenter_form_view_inherit"/>
        <field name="arch" type="xml">

            <xpath expr="//page[@string='Information']" position="after">
                <page string="Input/Output Products">                                                         
                    <group>                                                                         
                        <group string="Input Products">                                               
                            <field name="mrp_workorder_variation_line_ids" nolabel="1"
                                attrs="{'readonly': [('state','!=','draft')]}">
                                <tree string="Input Product" editable="bottom">
                                    <field name="product_id"  
                                        on_change="on_change_product_uom(product_id)"/>
                                    <field name="product_uom"/>
                                    <field name="product_qty"/>                                        
                                </tree>
                                <form string="Input Product" version="7.0">
                                    <field name="product_id"/>                                        
                                    <field name="product_uom"/>                                        
                                    <field name="product_qty"/>                                        
                                </form>
                            </field>
                        </group>                                                                    
                    </group>                                                                        
                    <group>                                                                         
                        <group string="Output Products">                                               
                            <field name="mrp_workorder_variation_output_line_ids" nolabel="1"
                                 attrs="{'readonly': [('state','!=','startworking')]}">
                                <tree string="Output Product" editable="bottom">
                                    <field name="product_id" 
                                        on_change="on_change_product_uom(product_id)"/>
                                    <field name="product_uom"/>
                                    <field name="product_qty"/>                                        
                                </tree>
                                <form string="Output Product" version="7.0">
                                    <field name="product_id" />                                        
                                    <field name="product_uom"/>                                        
                                    <field name="product_qty"/>                                        
                                </form>
                            </field>
                        </group>                                                                    
                    </group>                                                                        

                </page>  
            </xpath>

        </field>
    </record>

关于为什么会发生这种情况的任何想法?

我也尝试继承原来的&lt;xpath expr="//page[@string='Information']",但结果相同,没有显示新页面。

提前致谢!

编辑

如果我把它改成这样:

`<record id="mrp_production_workcenter_form_view_inherit_3" model="ir.ui.view">
        <field name="name">MRP Production Work Book Block</field>
        <field name="model">book.block.code</field>
        <field name="inherit_id" ref="mrp_operations.mrp_production_workcenter_form_view_inherit"/>
        <field name="arch" type="xml">

            <xpath expr="//page[@string='Information']" position="after">
                <page string="Book Block">                                                         
                    <group>                                                                         
                        <group string="Book Block">                                               
                            <field name="name"/>
                            <field name="description"/>
                        </group>                                                                    
                    </group>                                               
                </page>  
            </xpath>

        </field>
    </record>`

原来的模块,还是没有显示新页面

【问题讨论】:

  • 原始视图在哪个模块中?在mrp??
  • 嗨,它在“mrp_operations”中
  • 然后 ref="mrp_operations.view_id_of _original_view_you_want_to_inherit"
  • 我知道,但是结果一样,没有显示新页面
  • 能否在xpath中添加这段代码--> &lt;xpath expr="//sheet/notbook/page[@string='Information']" position="after"

标签: python xpath openerp odoo-8


【解决方案1】:

我不认为您可以通过字符串属性选择页面。不知道为什么。我认为您可以使用命名页面。

尝试在页码//page[first()] 或//page[last()] 上进行选择,我很确定您也可以在第 n 页上进行选择。

您也可以尝试完全覆盖他们的视图,并将您的页面包含在他们已经使用的 xpath 中。在这种情况下,基本上完全复制他们的视图并命名空间 xml id。

 <record id="addon_namespacehere.mrp_production_workcenter_form_view_inherit_2" model="ir.ui.view">
    <field name="name">MRP Production Workcenter Line</field>
    <field name="model">mrp.production.workcenter.line</field>
    <field name="inherit_id" ref="mrp_operations.mrp_production_workcenter_form_view_inherit"/>
    <field name="arch" type="xml">

        <xpath expr="//page[@string='Information']" position="after">
            <page string="Input/Output Products">                                                         
                <group>                                                                         
                    <group string="Input Products">                                               
                        <field name="mrp_workorder_variation_line_ids" nolabel="1"
                            attrs="{'readonly': [('state','!=','draft')]}">
                            <tree string="Input Product" editable="bottom">
                                <field name="product_id"  
                                    on_change="on_change_product_uom(product_id)"/>
                                <field name="product_uom"/>
                                <field name="product_qty"/>                                        
                            </tree>
                            <form string="Input Product" version="7.0">
                                <field name="product_id"/>                                        
                                <field name="product_uom"/>                                        
                                <field name="product_qty"/>                                        
                            </form>
                        </field>
                    </group>                                                                    
                </group>                                                                        
                <group>                                                                         
                    <group string="Output Products">                                               
                        <field name="mrp_workorder_variation_output_line_ids" nolabel="1"
                             attrs="{'readonly': [('state','!=','startworking')]}">
                            <tree string="Output Product" editable="bottom">
                                <field name="product_id" 
                                    on_change="on_change_product_uom(product_id)"/>
                                <field name="product_uom"/>
                                <field name="product_qty"/>                                        
                            </tree>
                            <form string="Output Product" version="7.0">
                                <field name="product_id" />                                        
                                <field name="product_uom"/>                                        
                                <field name="product_qty"/>                                        
                            </form>
                        </field>
                    </group>                                                                    
                </group>                                                                        

            </page> 
           <page string="Book Block">                                                         
                <group>                                                                         
                    <group string="Book Block">                                               
                        <field name="name"/>
                        <field name="description"/>
                    </group>                                                                    
                </group>                                                   
            </page>   
        </xpath>

    </field>
</record>

【讨论】:

  • 嗨,但我不认为这是可用的,因为我有 6 个其他自定义模块应该继承这个视图,我不知道如何与每个人一起做这个,还有,如果页码不存在,我在哪里可以找到?
  • 不,编辑原始视图并不是一个好主意。但是,您可以创建一个视图并实际使用原始视图中使用的相同 xml_id。因此,如果原始视图 ID 是 addon_name.view_id 您可以调用您的视图 addon_name.view_id 并且您的视图将被使用而不是原始视图。然后你就不必使用 xpath 来注入你的内容了。
  • 当然我明白了,但是模型不同,book_block_code 是另一个模型,所以不会加载这些字段,除非我用相同的_name 调用它,对吧?对于其他模块,我不明白如何实现这一点,现在就尝试
猜你喜欢
  • 2015-10-21
  • 2015-08-23
  • 1970-01-01
  • 1970-01-01
  • 2018-07-14
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
  • 2021-11-20
相关资源
最近更新 更多