2017-10-06 70 views
0

我需要在Odoo 10中擴展一個表單(stock.view_inventory_form)。表單中有一個子樹填充了來自另一個模型的相關記錄。下面是我想改變原始形式的一部分:odoo 10:擴展相關記錄的視圖樹(inventory.stock.line)

<field name="line_ids" string="Inventory Details" context="{'default_location_id': location_id, 'default_product_id': product_id, 'default_prod_lot_id': lot_id, 'default_package_id': package_id, 'default_partner_id': partner_id}" mode="tree,kanban"> 
    <tree string="Inventory Details" editable="bottom" decoration-info="product_qty != theoretical_qty" decoration-danger="theoretical_qty &lt; 0"> 
    <field name="product_id" domain="[('type','=','product')]"/> 
    <field name="product_uom_id" string="UoM" groups="product.group_uom"/> 
    <field name="location_id" domain="[('id', 'child_of', parent.location_id)]" groups="stock.group_stock_multi_locations"/> 
    <field name="prod_lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/> 
    <field name="package_id" domain="['|', ('location_id','=', False), ('location_id', '=', location_id)]" groups="stock.group_tracking_lot"/> 
    <field name="partner_id" groups="stock.group_tracking_owner"/> 
    <field name="theoretical_qty" readonly="1"/> 
    <field name="product_qty" string="Real Quantity"/> 
    <field name="state" invisible="True"/> 
    </tree> 
</field> 

哪裏line_ids是從相關模型(stock.inventory.line)的字段。所以我擴展了以下的模式:

class stock_inventory_line(models.Model): 
    _inherit = 'stock.inventory.line' 

    x_container_details = fields.Char('Container details') 
    x_wagon_no = fields.Char('Wagon No') 
    x_seal_no = fields.Char('Seal No') 
    x_invoice_no = fields.Integer('Invoice No') 
    x_net_weight = fields.Integer('Net weight') 
    x_gross_weight = fields.Integer('Gross Weight') 

然後我試着用下面的代碼擴展形式:

<record id="view_form_todo_task_inherited" model="ir.ui.view"> 
    <field name="name">Test</field> 
    <field name="model">stock.inventory</field> 
    <field name="inherit_id" ref="stock.view_inventory_form"/> 
    <field name="arch" type="xml"> 
     <field name="line_ids"> 
     <field name="x_container_details"/> 
     <field name="x_wagon_no"/> 
     </field>   
    </field> 
    </record> 

Odoo沒有返回任何錯誤,但我的字段是不是在顯示(子)樹的形式..我做錯了什麼? 感謝任何人都可以提供幫助!

回答

1

這不是正確的擴展視圖,你應該看看documentation

你需要指定的位置是要添加或更換領域,這是在列表的末尾插入區域的例子:

<record id="view_form_todo_task_inherited" model="ir.ui.view"> 
<field name="name">Test</field> 
<field name="model">stock.inventory</field> 
<field name="inherit_id" ref="stock.view_inventory_form"/> 
<field name="arch" type="xml"> 
    <!-- to insert your fields at the end of the list --> 
    <xpath expr="//tree/field[@name='state']" position="after" > 
     <field name="x_container_details"/> 
     <field name="x_wagon_no"/> 
    </xpath> 
</field> 

我希望這可以是有益的爲你。

+0

謝謝胡安薩爾塞多!有用。 我以前在我的示例中沒有使用xpath的方式擴展了非相關字段,所以我認爲有一種方法可以在不使用xpath的情況下執行。 – GiulioG

+0

我很高興聽到這個消息,是的,你不能使用'xpath',但你也應該指出位置,>,但我認爲使用'xpath'更有用直觀地使用比「領域」,併爲您的情況下,如果有更多的'狀態'定義,你可以麻煩找到你想使用的字段(狀態),這就是爲什麼我指定'/ /樹/字段'路徑。 –