Search code examples
pythontreeviewodooodoo-11

How to use same field more than once in a form?


What would the view xml look like for a module that needed to use the same field more than once?

For example. In my scenario i'm inheriting the view and want to display some fields in new page as you can see in the code. move_lines is already used in the parent view so im not get the required output.

<xpath expr="/form/sheet/notebook/page[3]" position="after">
     <page string="Tracking Info">
          <field name="move_lines">
                 <tree string="Stock Moves" editable="bottom" create="false" delete="false">
                      <field name="product_id" readonly="True" required="1"/>
                      <field name="tracking_no"/>
                  </tree>
           </field>
    </page>
</xpath>

Is there a better way of doing this?


Solution

  • I did some search and the only way to this is creating related field.

    class stock_picking(models.Model):
        _inherit = 'stock.picking'
    
        move_lines_d = fields.One2many('stock.move', related='move_lines')
    

    And use that field in the xml

    <xpath expr="/form/sheet/notebook/page[3]" position="after">
                      <page string="Tracking Info">
                                <field name="move_lines_d">
                                    <tree string="Stock Moves" editable="bottom" create="false" delete="false">
                                        <field name="state" invisible="1" readonly="0"/>
                                        <field name="product_id" readonly="True" required="1"/>
    
                                        <field name="moveline_partner" readonly="True"/>
                                        <field name="moveline_partner_address" readonly="True"/>
                                        <field name="tracking_no"/>
    
                                        <!--<field name="product_uom_qty" string="Initial Demand" readonly="True"/>-->
                                        <!--<field name="reserved_availability" string="Reserved" readonly="True"/>-->
                                        <field name="quantity_done" string="Done" readonly="True"/>
                                        <!--<field name="product_uom" readonly="True" string="Unit of Measure" groups="product.group_uom"/>-->
                                    </tree>
                                </field>
                            </page>
                  </xpath>