From 6f87a849acd716e5ee66d93e4cbea548de5dc8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Wed, 28 Oct 2020 14:19:23 +0000 Subject: [PATCH] [FIX] stock: fix picking_type_id of stock move. The picking_type_id of a stock move can differ of the related picking: - Create and save a draft transfer with a stock move - Change the picking_type_id and save - The picking_type of moves won't be the same than the one on the stock picking. Fix force the picking_type_id of moves_lines in the picking `onchange_picking_type` method. Same issue can appear in multi company situation, fix it too. task-2372196 closes odoo/odoo#61574 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_picking.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 8c6cdf7379c..4645ce7a9af 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -568,7 +568,7 @@ class Picking(models.Model): @api.onchange('picking_type_id', 'partner_id') def onchange_picking_type(self): - if self.picking_type_id: + if self.picking_type_id and self.state == 'draft': self = self.with_company(self.company_id) if self.picking_type_id.default_location_src_id: location_id = self.picking_type_id.default_location_src_id.id @@ -584,11 +584,13 @@ class Picking(models.Model): else: location_dest_id, supplierloc = self.env['stock.warehouse']._get_partner_locations() - if self.state == 'draft': - self.location_id = location_id - self.location_dest_id = location_dest_id + self.location_id = location_id + self.location_dest_id = location_dest_id + (self.move_lines | self.move_ids_without_package).update({ + "picking_type_id": self.picking_type_id, + "company_id": self.company_id, + }) - # TDE CLEANME move into onchange_partner_id if self.partner_id and self.partner_id.picking_warn: if self.partner_id.picking_warn == 'no-message' and self.partner_id.parent_id: partner = self.partner_id.parent_id