[FIX] rma: improve check on rule selection during procurement

Fixes #274

Thanks to @florian-dacosta for suggesting this approach.
This commit is contained in:
Stefan Rijnhart
2022-06-24 12:07:31 +02:00
committed by Carlos Vallés Fuster
parent d3da7fe3cc
commit b96eff7aac
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