Skip to Content
Menu
This question has been flagged
2 Replies
4746 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

Avatar
Discard

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"), }

Best Answer

Hi,

Try the following:

in .py file:

class stock_picking(osv.osv):
    _inherit="stock.picking" 
 
_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" />
</field>
</field>
</record>

Hope this helps

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 23
1489
0
Mar 20
1837
4
Jan 16
5626
0
May 23
1770
3
Jan 23
2029