Hamza Ali
Hamza Ali

Reputation: 390

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?

Upvotes: 1

Views: 796

Answers (3)

Hamza Ali
Hamza Ali

Reputation: 390

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>

Upvotes: 3

Adan Cortes
Adan Cortes

Reputation: 1068

<record model="ir.ui.view" id="view_picking_form_with_double_move_lines">
  <field name="name">stark product</field>
  <field name="model">stock.picking</field>
  <field name="mode">extension</field>
  <field name="priority" eval="50"/>
  <field name="inherit_id" ref="stock.view_picking_form"/>
  <field name="arch" type="xml">
    <xpath expr="/form/sheet/notebook/page[3]" position="after">
      <page string="Tracking Info">
        <field name="move_lines" widget="one2many"/>
      </page>
    </xpath>
</field>

after before view

Upvotes: 0

CZoellner
CZoellner

Reputation: 14801

Actually that is not possible with a vanilla (not customized) Odoo, and i don't know about any customization that's fulfilling this requirement.

Upvotes: 0

Related Questions