This question has been flagged

Python side :

On stock_picking there is of course a one2many relation with stock moves.

'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),

I added a field on stock_move like this (with custom module): 

class StockMove(osv.osv):

    _inherit = 'stock.move'
    _columns = {
         'prix_unitaire': fields.float('Prix unitaire'),
        }
StockMove()

Now I want to add this field on the view side, on the one2many move lines relationship with stock_picking.

Explanations about View side :

On "view picking_out_form" the stock move lines of "view_picking_form" are overrided like this : 

        <record id="view_picking_out_form" model="ir.ui.view">
            <field name="name">stock.picking.out.form</field>
            <field name="model">stock.picking.out</field>
            <field name="inherit_id" ref="view_picking_form"/>
            <field name="arch" type="xml">

               <xpath expr="//field[@name='move_lines']" position="replace">
                    <field name="move_lines" string="Stock Move" context="{'address_out_id': partner_id, 'picking_type': 'out', 'form_view_ref':'stock.view_move_picking_form', 'tree_view_ref':'stock.view_move_picking_tree'}" options='{"reload_on_button": true}'>
                    </field>
                </xpath>

 

          </field>

       </record>

Because "view_picking_form" is the main view, giving possiblities to create several views based on it. openerp creates the "picking_out_form" ( delivery orders) and "picking_in_form" for any incoming shipements.

I noticed that there is no tree for the move_lines field, i expected to find a structure like this : 

                <xpath expr="//field[@name='move_lines']" position="replace">
                    <field name="move_lines" string="Stock Move" context="{'address_out_id': partner_id, 'picking_type': 'out', 'form_view_ref':'stock.view_move_picking_form', 'tree_view_ref':'stock.view_move_picking_tree'}" options='{"reload_on_button": true}'>
                        <tree string="Move lines Valued" editable="bottom">
                            <field name="product_id"/>
                            <field name="product_qty"/>
                            <field name="product_uom"/>
                            <field name="location_dest_id"/>
                            <field name="state"/>
                        </tree>
                    </field>
                </xpath>

This structure gives possibility to customize the one2many stock_move relation.

Why the move_lines are implemented like this ?

How to customize it ? is there anyway to override this kind of one2many view implementation ?

The purpose is to add the new field I have created on stock.move object, on the one2many field.

Any suggestions please ?

Avatar
Discard
Best Answer

The tree structure is not compulsory.  In the code that you have posted, it would take the view with XML ID stock.view_move_picking_form as form view (form_view_ref) and stock.view_move_picking_tree as tree view (tree_view_ref).  This is more economical way of defining views if the same views are used in multiple locations.  Even if the form_view_ref and/or tree_view_ref is not defined, it is still OK.  By default the view processor will take the first view that matches the type and model, ordered by priority and name.

So, in your case, you need to inherit stock.view_move_picking_form or stock.view_move_picking_tree as you wish.

Avatar
Discard
Author

Yes, Thank you very much. I've tested it and it works.

Glad to help. Just ensure that you really wanted to add the field to every single stock.move view that uses stock.view_move_picking_form or stock.view_move_picking_tree. If you don't want that, then replace the move_lines field without the form_view_ref and/or tree_view_ref and define your own tree/form views there.

Author Best Answer

So to summarise : There is tree ways to call a view for a one2many composant :

1. Calling it directly, and it can be tree or form view.

2. Calling it with 'form_view_ref' 'tree_view_ref' on context attribute for the one2many field.

3. Do not even specify  'form_view_ref' and 'tree_view_ref', and rely on views priorities defined for the object.

Thanks.

 

Avatar
Discard