Odoo Help


Pass a value from sale.order to stock.picking via server-actions

Marc Wagener
on 9/15/15, 3:17 AM 1,075 views

I want update a field in stock.picking with a value from sale.order.

in sale.order : 'client_order_ref'.

in stock.picking: I've created a new field 'x_order_description'

my server action code on update:

active_id = context.get('active_id')

sale_obj = self.pool.get('sale.order')

picking_obj = self.pool.get('stock.picking')

picking_ids = picking_obj.search(cr, uid, [('sale_id', '=', active_id)], context=context)  #this returns all the pickings!

if picking_ids:

sale_record = self.browse(cr, uid, active_id, context=context)

picking_obj.write(cr, uid, picking_ids, {'x_order_description': sale_record.client_order_ref}, context=context)

the problem:

when updating the full table gets the new value of 'x_order_description', but I want only update the corresponding pickings

you can use the fields.related as like below: class stock_picking(osv.osv): _name = 'stock.picking' _inherit = 'stock.picking' _columns = { 'x_project_id' : fields.related('sale_id','x_project_id',type="char", readonly="True", string="Project ID"), #'x_project_id' : fields.char(string="Project ID"), }

Sayed Anisul Hoque
on 10/29/15, 1:15 AM

Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/29/15, 1:45 AM


Try the following:

in .py file:

class stock_picking(osv.osv):
_columns ={
'x_order_description': fields.related('sale_id', 'client_order_ref', string='Order Description', type='char', size=64, required=True, readonly=True)


in your xml file:

<record id="view_picking_form_form_inherited" model="ir.ui.view">
<field name="name">view.picking.form.view.inherited</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="x_order_description" />

Hope this helps

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: 9/15/15, 3:17 AM
Seen: 1075 times
Last updated: 10/29/15, 1:46 AM