Odoo Help


Views Inheritance : Override Stock move Lines on "Stock_picking_out" View (Delivery Orders) [v7]

Yassine TEIMI
on 1/23/15, 5:35 AM 1,949 views

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'),

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}'>




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"/>

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 ?




| 5 3 6
Jakarta, Indonesia
On 1/23/15, 6:03 AM

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.

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

Yassine TEIMI
on 1/23/15, 7:21 AM

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.

on 1/24/15, 1:03 AM
Yassine TEIMI
On 1/23/15, 7:23 AM

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.



About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 1/23/15, 5:35 AM
Seen: 1949 times
Last updated: 3/16/15, 8:10 AM