[FIX] stock: find putaway location of correct dest_location

Previously when the onchange method find a putaway location for a sml, we
find a putaway location of the location_dest on the sml. However, the
location may already be a result of last computation of putaway
location. In this commit, we always find putaway location of the default
destination location.

Task-2614519

X-original-commit: a96fb8e9d2a57b67666ca3b29c9313aba83cdb91
Part-of: odoo/odoo#80519
This commit is contained in:
yhu-odoo
2021-11-30 14:31:06 +00:00
parent d04a5b5c8c
commit 22df4c807c
+14 -3
View File
@@ -131,14 +131,18 @@ class StockMoveLine(models.Model):
def _onchange_result_package_id(self):
if self.result_package_id:
if not self.id and self.user_has_groups('stock.group_stock_multi_locations'):
self.location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id, package=self.result_package_id)
default_dest_location = self._get_default_dest_location()
self.location_dest_id = default_dest_location._get_putaway_strategy(
self.product_id, package=self.result_package_id, packaging=self.move_id.product_packaging_id)
@api.onchange('product_id', 'product_uom_id')
def _onchange_product_id(self):
if self.product_id:
if not self.id and self.user_has_groups('stock.group_stock_multi_locations') and not self.result_package_id:
qty_done = self.product_uom_id._compute_quantity(self.qty_done, self.product_id.uom_id)
self.location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id, qty_done)
default_dest_location = self._get_default_dest_location()
self.location_dest_id = default_dest_location._get_putaway_strategy(
self.product_id, qty_done, packaging=self.move_id.product_packaging_id)
if self.picking_id:
product = self.product_id.with_context(lang=self.picking_id.partner_id.lang or self.env.user.lang)
self.description_picking = product._get_description(self.picking_id.picking_type_id)
@@ -202,7 +206,9 @@ class StockMoveLine(models.Model):
if self.qty_done:
qty_done = self.product_uom_id._compute_quantity(self.qty_done, self.product_id.uom_id)
if not self.id and self.user_has_groups('stock.group_stock_multi_locations') and not self.result_package_id:
self.location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id, qty_done)
default_dest_location = self._get_default_dest_location()
self.location_dest_id = default_dest_location._get_putaway_strategy(
self.product_id, qty_done, packaging=self.move_id.product_packaging_id)
if self.product_id.tracking == 'serial':
qty_done = self.product_uom_id._compute_quantity(self.qty_done, self.product_id.uom_id)
if float_compare(qty_done, 1.0, precision_rounding=self.product_id.uom_id.rounding) != 0:
@@ -210,6 +216,11 @@ class StockMoveLine(models.Model):
res['warning'] = {'title': _('Warning'), 'message': message}
return res
def _get_default_dest_location(self):
if self.env.context.get('default_location_dest_id'):
return self.env['stock.location'].browse([self.env.context.get('default_location_dest_id')])
return self.move_id.location_dest_id or self.picking_id.location_dest_id or self.location_dest_id
def init(self):
if not tools.index_exists(self._cr, 'stock_move_line_free_reservation_index'):
self._cr.execute("""