Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions rma_lot/tests/test_rma_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def setUpClass(cls):
cls.product = cls.env["product.product"].create(
{"name": "test_product", "type": "product", "tracking": "lot"}
)
cls.product2 = cls.env["product.product"].create(
{"name": "test_product 2", "type": "product", "tracking": "lot"}
)
cls.lot_1 = cls.env["stock.lot"].create(
{"name": "000001", "product_id": cls.product.id}
)
Expand Down Expand Up @@ -101,3 +104,34 @@ def test_rma_form(self):
self.assertEqual(rma_form.product_id, self.product)
rma_form.product_id = self.env.ref("product.product_product_4")
self.assertFalse(rma_form.lot_id)

def test_different_return_product(self):
"""if the return product is different than the rma product, the lot can't be set
on the reception move neither on the rma"""
self.operation.different_return_product = True
stock_return_picking_form = Form(
self.env["stock.return.picking"].with_context(
active_ids=self.picking.ids,
active_id=self.picking.id,
active_model="stock.picking",
)
)
stock_return_picking_form.create_rma = True
stock_return_picking_form.rma_operation_id = self.operation
with self.assertRaises(
AssertionError, msg="return_product_id is a required field"
):
stock_return_picking_form.save()
with stock_return_picking_form.product_return_moves.edit(0) as return_line:
return_line.return_product_id = self.product2
with stock_return_picking_form.product_return_moves.edit(1) as return_line:
return_line.return_product_id = self.product2
return_wizard = stock_return_picking_form.save()
self.assertEqual(len(return_wizard.product_return_moves), 2)
return_wizard.create_returns()
self.assertEqual(self.picking.rma_count, 2)
rmas = self.picking.move_ids.rma_ids
self.assertTrue(rmas.exists())
self.assertTrue(rmas.reception_move_id.exists())
self.assertFalse(rmas.lot_id)
self.assertFalse(rmas.reception_move_id.restrict_lot_id)
4 changes: 3 additions & 1 deletion rma_lot/wizards/stock_return_picking_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class StockReturnPickingLine(models.TransientModel):
_inherit = "stock.return.picking.line"

def _prepare_rma_vals(self):
self.ensure_one()
vals = super()._prepare_rma_vals()
vals.update({"lot_id": self.lot_id.id})
if not self.rma_operation_id.different_return_product:
vals.update({"lot_id": self.lot_id.id})
return vals
23 changes: 23 additions & 0 deletions rma_sale_lot/tests/test_rma_sale_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def setUpClass(cls):
cls.product = cls.env["product.product"].create(
{"name": "test_product", "type": "product", "tracking": "lot"}
)
cls.product2 = cls.env["product.product"].create(
{"name": "test_product 2", "type": "product", "tracking": "lot"}
)
cls.lot_1 = cls.env["stock.lot"].create(
{"name": "000001", "product_id": cls.product.id}
)
Expand Down Expand Up @@ -64,3 +67,23 @@ def test_full_return_after_partial_return(self):
rma_2 = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
self.assertEqual(rma_2.reception_move_id.restrict_lot_id, self.lot_2)
self.assertEqual(rma_2.product_uom_qty, 1)

def test_return_different_product(self):
self.operation.different_return_product = True
wizard = self._rma_sale_wizard(self.sale_order)
line_1 = wizard.line_ids.filtered(
lambda line, lot=self.lot_1: line.lot_id == lot
)
line_2 = wizard.line_ids.filtered(
lambda line, lot=self.lot_2: line.lot_id == lot
)
line_1.return_product_id = self.product2
line_2.return_product_id = self.product2
self.assertEqual(line_1.quantity, 1)
self.assertEqual(line_2.quantity, 2)
line_2.quantity = 1
rma = self.env["rma"].search(wizard.create_and_open_rma()["domain"])
self.assertTrue(rma.exists())
self.assertTrue(rma.reception_move_id.exists())
self.assertFalse(rma.lot_id)
self.assertFalse(rma.reception_move_id.restrict_lot_id)
3 changes: 2 additions & 1 deletion rma_sale_lot/wizards/sale_order_line_rma_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def _compute_lots_visible(self):
def _prepare_rma_values(self):
self.ensure_one()
values = super()._prepare_rma_values()
values["lot_id"] = self.lot_id.id
if not self.operation_id.different_return_product:
values["lot_id"] = self.lot_id.id
return values