Odoo Help

Welcome!

This community 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.

0

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

By
Yassine TEIMI
on 1/23/15, 5:35 AM 1,119 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'),
        }
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 ?

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
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.

Ivan
on 1/24/15, 1:03 AM
0
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.

Thanks.

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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