Skip to content

Commit 3216ec6

Browse files
committed
[FIX] don't restrict lot if return product is different
1 parent 157f3dc commit 3216ec6

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

rma_lot/tests/test_rma_lot.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def setUpClass(cls):
1414
cls.product = cls.env["product.product"].create(
1515
{"name": "test_product", "type": "product", "tracking": "lot"}
1616
)
17+
cls.product2 = cls.env["product.product"].create(
18+
{"name": "test_product 2", "type": "product", "tracking": "lot"}
19+
)
1720
cls.lot_1 = cls.env["stock.lot"].create(
1821
{"name": "000001", "product_id": cls.product.id}
1922
)
@@ -101,3 +104,34 @@ def test_rma_form(self):
101104
self.assertEqual(rma_form.product_id, self.product)
102105
rma_form.product_id = self.env.ref("product.product_product_4")
103106
self.assertFalse(rma_form.lot_id)
107+
108+
def test_different_return_product(self):
109+
"""if the return product is different than the rma product, the lot can't be set
110+
on the reception move neither on the rma"""
111+
self.operation.different_return_product = True
112+
stock_return_picking_form = Form(
113+
self.env["stock.return.picking"].with_context(
114+
active_ids=self.picking.ids,
115+
active_id=self.picking.id,
116+
active_model="stock.picking",
117+
)
118+
)
119+
stock_return_picking_form.create_rma = True
120+
stock_return_picking_form.rma_operation_id = self.operation
121+
with self.assertRaises(
122+
AssertionError, msg="return_product_id is a required field"
123+
):
124+
stock_return_picking_form.save()
125+
with stock_return_picking_form.product_return_moves.edit(0) as return_line:
126+
return_line.return_product_id = self.product2
127+
with stock_return_picking_form.product_return_moves.edit(1) as return_line:
128+
return_line.return_product_id = self.product2
129+
return_wizard = stock_return_picking_form.save()
130+
self.assertEqual(len(return_wizard.product_return_moves), 2)
131+
return_wizard.create_returns()
132+
self.assertEqual(self.picking.rma_count, 2)
133+
rmas = self.picking.move_ids.rma_ids
134+
self.assertTrue(rmas.exists())
135+
self.assertTrue(rmas.reception_move_id.exists())
136+
self.assertFalse(rmas.lot_id)
137+
self.assertFalse(rmas.reception_move_id.restrict_lot_id)

rma_lot/wizards/stock_return_picking_line.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class StockReturnPickingLine(models.TransientModel):
99
_inherit = "stock.return.picking.line"
1010

1111
def _prepare_rma_vals(self):
12+
self.ensure_one()
1213
vals = super()._prepare_rma_vals()
13-
vals.update({"lot_id": self.lot_id.id})
14+
if not self.rma_operation_id.different_return_product:
15+
vals.update({"lot_id": self.lot_id.id})
1416
return vals

rma_sale_lot/tests/test_rma_sale_lot.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def setUpClass(cls):
1111
cls.product = cls.env["product.product"].create(
1212
{"name": "test_product", "type": "product", "tracking": "lot"}
1313
)
14+
cls.product2 = cls.env["product.product"].create(
15+
{"name": "test_product 2", "type": "product", "tracking": "lot"}
16+
)
1417
cls.lot_1 = cls.env["stock.lot"].create(
1518
{"name": "000001", "product_id": cls.product.id}
1619
)
@@ -64,3 +67,23 @@ def test_full_return_after_partial_return(self):
6467
rma_2 = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
6568
self.assertEqual(rma_2.reception_move_id.restrict_lot_id, self.lot_2)
6669
self.assertEqual(rma_2.product_uom_qty, 1)
70+
71+
def test_return_different_product(self):
72+
self.operation.different_return_product = True
73+
wizard = self._rma_sale_wizard(self.sale_order)
74+
line_1 = wizard.line_ids.filtered(
75+
lambda line, lot=self.lot_1: line.lot_id == lot
76+
)
77+
line_2 = wizard.line_ids.filtered(
78+
lambda line, lot=self.lot_2: line.lot_id == lot
79+
)
80+
line_1.return_product_id = self.product2
81+
line_2.return_product_id = self.product2
82+
self.assertEqual(line_1.quantity, 1)
83+
self.assertEqual(line_2.quantity, 2)
84+
line_2.quantity = 1
85+
rma = self.env["rma"].search(wizard.create_and_open_rma()["domain"])
86+
self.assertTrue(rma.exists())
87+
self.assertTrue(rma.reception_move_id.exists())
88+
self.assertFalse(rma.lot_id)
89+
self.assertFalse(rma.reception_move_id.restrict_lot_id)

rma_sale_lot/wizards/sale_order_line_rma_wizard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ def _compute_lots_visible(self):
1919
def _prepare_rma_values(self):
2020
self.ensure_one()
2121
values = super()._prepare_rma_values()
22-
values["lot_id"] = self.lot_id.id
22+
if not self.operation_id.different_return_product:
23+
values["lot_id"] = self.lot_id.id
2324
return values

0 commit comments

Comments
 (0)