diff --git a/addons/stock/models/product_strategy.py b/addons/stock/models/product_strategy.py index 3f73357c855..b8ea23e35ce 100644 --- a/addons/stock/models/product_strategy.py +++ b/addons/stock/models/product_strategy.py @@ -96,8 +96,13 @@ class StockPutawayRule(models.Model): raise UserError(_("Changing the company of this record is forbidden at this point, you should rather archive it and create a new one.")) return super(StockPutawayRule, self).write(vals) - def _get_putaway_location(self, product, quantity=0, package=None, qty_by_location=None): - package_type = package and package.package_type_id or None + def _get_putaway_location(self, product, quantity=0, package=None, packaging=None, qty_by_location=None): + # find package type on package or packaging + package_type = self.env['stock.package.type'] + if package: + package_type = package.package_type_id + elif packaging: + package_type = packaging.package_type_id checked_locations = set() for putaway_rule in self: diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index 8437f1b7e68..e8e1dbbca0e 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -262,7 +262,7 @@ class Location(models.Model): for values in quant_data: qty_by_location[values['location_id'][0]] += values['quantity'] - putaway_location = putaway_rules._get_putaway_location(product, quantity, package, qty_by_location) + putaway_location = putaway_rules._get_putaway_location(product, quantity, package, packaging, qty_by_location) if not putaway_location: putaway_location = locations[0] if locations and self.usage == 'view' else self