From febab232030794883d1afb5f80d77814082aa248 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Thu, 19 Sep 2019 10:07:43 +0000 Subject: [PATCH] [FIX] stock: missing company id on picking move When creating a new picking, in case the user creates stock.move before define the picking type, the move has no `company_id`. Also, if they changes the picking type for an another company picking type, the `company_id`of the move already created doesn't corresponding anymore to the `company_id`of the picking anymore. So, when create a new picking, we now insure the write the `company_id` of new stock.move to be sure these cases was handle. closes odoo/odoo#37130 Signed-off-by: Simon Lejeune (sle) --- addons/stock/models/stock_picking.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 931f789cc08..e78a9aed406 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -528,7 +528,6 @@ class Picking(models.Model): if self.state == 'draft': self.location_id = location_id self.location_dest_id = location_dest_id - self.company_id = self.picking_type_id.company_id # TDE CLEANME move into onchange_partner_id if self.partner_id and self.partner_id.picking_warn: @@ -561,6 +560,14 @@ class Picking(models.Model): if len(move) == 3 and move[0] == 0: move[2]['location_id'] = vals['location_id'] move[2]['location_dest_id'] = vals['location_dest_id'] + # When creating a new picking, a move can have no `company_id` (create before + # picking type was defined) or a different `company_id` (the picking type was + # changed for an another company picking type after the move was created). + # So, we define the `company_id` in one of these cases. + picking_type = self.env['stock.picking.type'].browse(vals['picking_type_id']) + if 'picking_type_id' not in move[2] or move[2]['picking_type_id'] != picking_type.id: + move[2]['picking_type_id'] = picking_type.id + move[2]['company_id'] = picking_type.company_id.id res = super(Picking, self).create(vals) res._autoconfirm_picking() return res