Skip to content

Commit a9a9c81

Browse files
committed
[IMP] repair_preparation: skip preparation flow for customer location repairs
1 parent 47b4e91 commit a9a9c81

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

repair_preparation/models/repair_order.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ class RepairOrder(models.Model):
2929
"stock.picking", compute="_compute_preparation_picking_ids"
3030
)
3131
repair_preparation_enabled = fields.Boolean(
32-
related="warehouse_id.repair_preparation_enabled"
32+
compute="_compute_repair_preparation_enabled"
3333
)
3434

35+
@api.depends("warehouse_id.repair_preparation_enabled", "location_id.usage")
36+
def _compute_repair_preparation_enabled(self):
37+
for rec in self:
38+
rec.repair_preparation_enabled = bool(
39+
rec.warehouse_id.repair_preparation_enabled
40+
and rec.location_id.usage != "customer"
41+
)
42+
3543
@api.depends("warehouse_id", "repair_preparation_enabled")
3644
def _compute_preparation_picking_type_id(self):
3745
for rec in self:
@@ -106,11 +114,23 @@ def _run_preparation_procurements(self, operations):
106114
)
107115

108116
def action_validate(self):
109-
res = super().action_validate()
110-
for rec in self:
111-
if not rec.repair_preparation_enabled:
117+
"""repairs performed at a customer location don't require a preparation flow
118+
and do not need to check available quantities (handled in super)"""
119+
customer_repairs = self.filtered(
120+
lambda repair: repair.location_id.usage == "customer"
121+
)
122+
non_customer_repairs = self.filtered(
123+
lambda repair: repair.location_id.usage != "customer"
124+
)
125+
res = customer_repairs.action_repair_confirm()
126+
if not non_customer_repairs:
127+
return res
128+
res = super(RepairOrder, non_customer_repairs).action_validate()
129+
for repair in non_customer_repairs:
130+
if not repair.repair_preparation_enabled:
112131
continue
113-
rec._run_preparation_procurements(rec.operations)
132+
repair._run_preparation_procurements(repair.operations)
133+
114134
return res
115135

116136
def action_repair_end(self):

repair_preparation/tests/test_repair_preparation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,16 @@ def test_update_repair_line_after_preparation(self):
212212
self._do_picking(self.repair.preparation_picking_ids)
213213
self.assertEqual(self.line.location_id, self.prep_loc)
214214
self.assertEqual(self.line.lot_id, self.lot)
215+
216+
def test_preparation_disabled_when_reparation_location_is_customer(self):
217+
"""If the repair location is a customer location,
218+
products are consumed without a preparation picking"""
219+
self.warehouse.repair_preparation_enabled = True
220+
self.assertTrue(self.repair.repair_preparation_enabled)
221+
customer_location = self.env.ref("stock.stock_location_customers")
222+
self.repair.location_id = customer_location
223+
self.assertFalse(self.repair.repair_preparation_enabled)
224+
self.repair.action_validate()
225+
self.assertFalse(self.repair.preparation_picking_ids)
226+
self.repair.action_repair_start()
227+
self.assertFalse(self.line.preparation_move_ids)

0 commit comments

Comments
 (0)