[IMP] stock: smart putaway for packaging
Apply smart putaway rules on move with packaging. Task-2357259 PR #68654
This commit is contained in:
@@ -197,13 +197,18 @@ class Location(models.Model):
|
||||
domain = ['|', ('barcode', operator, name), ('complete_name', operator, name)]
|
||||
return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
|
||||
|
||||
def _get_putaway_strategy(self, product, quantity=0, package=None):
|
||||
def _get_putaway_strategy(self, product, quantity=0, package=None, packaging=None):
|
||||
"""Returns the location where the product has to be put, if any compliant
|
||||
putaway strategy is found. Otherwise returns self.
|
||||
The quantity should be in the default UOM of the product, it is used when
|
||||
no package is specified.
|
||||
"""
|
||||
package_type = package and package.package_type_id or self.env['stock.package.type']
|
||||
# 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
|
||||
|
||||
putaway_rules = self.env['stock.putaway.rule']
|
||||
putaway_rules |= self.putaway_rule_ids.filtered(lambda x: x.product_id == product and (package_type in x.package_type_ids or package_type == x.package_type_ids))
|
||||
|
||||
@@ -1056,7 +1056,7 @@ class StockMove(models.Model):
|
||||
if origin_move_line:
|
||||
location_dest = origin_move_line.location_dest_id
|
||||
else:
|
||||
location_dest = self.location_dest_id._get_putaway_strategy(self.product_id, quantity=1)
|
||||
location_dest = self.location_dest_id._get_putaway_strategy(self.product_id, quantity=1, packaging=self.product_packaging_id)
|
||||
move_line_vals = {
|
||||
'picking_id': self.picking_id.id,
|
||||
'location_dest_id': location_dest.id,
|
||||
@@ -1212,7 +1212,7 @@ class StockMove(models.Model):
|
||||
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
|
||||
self.ensure_one()
|
||||
# apply putaway
|
||||
location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id, quantity=quantity or 0).id
|
||||
location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id, quantity=quantity or 0, packaging=self.product_packaging_id).id
|
||||
vals = {
|
||||
'move_id': self.id,
|
||||
'product_id': self.product_id.id,
|
||||
|
||||
Reference in New Issue
Block a user