Merge pull request #275 from StefanRijnhart/fix/15.0/rma/check_route_flag_in_rule_constraint

[15.0][FIX] rma: improve check on rule selection during procurement
This commit is contained in:
Jordi Ballester Alomar
2022-06-26 19:05:44 +02:00
committed by GitHub
2 changed files with 13 additions and 13 deletions

View File

@@ -17,21 +17,21 @@ class ProcurementGroup(models.Model):
@api.model
def _get_rule(self, product_id, location_id, values):
"""Ensure that the selected rule is from the configured route"""
"""Ensure that the selected rule is valid for RMAs"""
res = super()._get_rule(product_id, location_id, values)
force_rule_ids = self.env.context.get("rma_force_rule_ids")
if force_rule_ids:
if res and res.id not in force_rule_ids:
rma_route_check = self.env.context.get("rma_route_check")
if rma_route_check:
if res and not res.route_id.rma_selectable:
raise ValidationError(
_(
"No rule found in this RMA's configured route for product "
"%(product)s and location %(location)s"
"No rule found for this product %(product)s and "
"location %(location)s that is valid for RMA operations."
)
% {
"product": product_id.default_code or product_id.name,
"location": location_id.complete_name,
}
)
# Don't enforce rules on any chained moves
force_rule_ids.clear()
# Don't enforce check on any chained moves
rma_route_check.clear()
return res

View File

@@ -144,10 +144,8 @@ class RmaMakePicking(models.TransientModel):
group = self.env["procurement.group"].create(pg_data)
if picking_type == "incoming":
qty = item.qty_to_receive
force_rule_ids = item.line_id.in_route_id.rule_ids.ids
else:
qty = item.qty_to_deliver
force_rule_ids = item.line_id.out_route_id.rule_ids.ids
values = self._get_procurement_data(item, group, qty, picking_type)
values = dict(values, rma_line_id=item.line_id, rma_id=item.line_id.rma_id)
# create picking
@@ -165,9 +163,11 @@ class RmaMakePicking(models.TransientModel):
)
procurements.append(procurement)
self.env["procurement.group"].with_context(
rma_force_rule_ids=force_rule_ids
).run(procurements)
# Trigger a route check with a mutable in the context that can be
# cleared after the first rule selection
self.env["procurement.group"].with_context(rma_route_check=[True]).run(
procurements
)
except UserError as error:
errors.append(error.args[0])
if errors: