2017-10-06 6 views
0

Odoo 10でフォーム(stock.view_inventory_form)を拡張する必要があります。フォームには、別のモデルの関連レコードが設定されたサブツリーがあります。 line_idsは、関連モデル(stock.inventory.line)からのフィールドである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> 

:ここで私は変更したい元のフォームの一部です。だから私は、次のようにモデルを拡張:

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

ありがとうJuan Salcedo!できます。 私は前にxpathなしで私の例で行ったように非関連フィールドを拡張していましたので、xpathなしでそれを行う方法があると仮定しました。 – GiulioG

+0

私はそれを聞いてうれしく、はい、あなたは 'xpath'を使うことができませんでしたが、位置を示すべきでもあります。直感的に 'field'よりも使いやすく、 'state'の定義が複数ある場合は、使用するフィールド(状態)を見つけるために問題が発生する可能性があります。そのため、 '// tree/field '経路。 –

関連する問題