mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] rma: improve check on rule selection during procurement
Fixes #274 Thanks to @florian-dacosta for suggesting this approach.
This commit is contained in:
committed by
Florian da Costa
parent
41ab6e0d52
commit
a4e20f6abb
@@ -17,21 +17,21 @@ class ProcurementGroup(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_rule(self, product_id, location_id, values):
|
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)
|
res = super()._get_rule(product_id, location_id, values)
|
||||||
force_rule_ids = self.env.context.get("rma_force_rule_ids")
|
rma_route_check = self.env.context.get("rma_route_check")
|
||||||
if force_rule_ids:
|
if rma_route_check:
|
||||||
if res and res.id not in force_rule_ids:
|
if res and not res.route_id.rma_selectable:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_(
|
_(
|
||||||
"No rule found in this RMA's configured route for product "
|
"No rule found for this product %(product)s and "
|
||||||
"%(product)s and location %(location)s"
|
"location %(location)s that is valid for RMA operations."
|
||||||
)
|
)
|
||||||
% {
|
% {
|
||||||
"product": product_id.default_code or product_id.name,
|
"product": product_id.default_code or product_id.name,
|
||||||
"location": location_id.complete_name,
|
"location": location_id.complete_name,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# Don't enforce rules on any chained moves
|
# Don't enforce check on any chained moves
|
||||||
force_rule_ids.clear()
|
rma_route_check.clear()
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -144,10 +144,8 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
group = self.env["procurement.group"].create(pg_data)
|
group = self.env["procurement.group"].create(pg_data)
|
||||||
if picking_type == "incoming":
|
if picking_type == "incoming":
|
||||||
qty = item.qty_to_receive
|
qty = item.qty_to_receive
|
||||||
force_rule_ids = item.line_id.in_route_id.rule_ids.ids
|
|
||||||
else:
|
else:
|
||||||
qty = item.qty_to_deliver
|
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 = 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)
|
values = dict(values, rma_line_id=item.line_id, rma_id=item.line_id.rma_id)
|
||||||
# create picking
|
# create picking
|
||||||
@@ -165,9 +163,11 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
procurements.append(procurement)
|
procurements.append(procurement)
|
||||||
self.env["procurement.group"].with_context(
|
# Trigger a route check with a mutable in the context that can be
|
||||||
rma_force_rule_ids=force_rule_ids
|
# cleared after the first rule selection
|
||||||
).run(procurements)
|
self.env["procurement.group"].with_context(rma_route_check=[True]).run(
|
||||||
|
procurements
|
||||||
|
)
|
||||||
except UserError as error:
|
except UserError as error:
|
||||||
errors.append(error.args[0])
|
errors.append(error.args[0])
|
||||||
if errors:
|
if errors:
|
||||||
|
|||||||
Reference in New Issue
Block a user