diff --git a/repair_stock_move/__manifest__.py b/repair_stock_move/__manifest__.py index 29ac4c4e..64fcddd7 100644 --- a/repair_stock_move/__manifest__.py +++ b/repair_stock_move/__manifest__.py @@ -10,7 +10,7 @@ "summary": "Ongoing Repair Stock Moves Definition in odoo", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/repair", - "depends": ["repair"], + "depends": ["repair", "stock_restrict_lot"], "data": [ "views/repair_order_views.xml", ], diff --git a/repair_stock_move/models/repair_order.py b/repair_stock_move/models/repair_order.py index 2d80f0fb..fa14c3d0 100644 --- a/repair_stock_move/models/repair_order.py +++ b/repair_stock_move/models/repair_order.py @@ -59,7 +59,7 @@ def _compute_show_check_availability(self): ) def _prepare_repair_stock_move(self): - return { + vals = { "name": self.name, "product_id": self.product_id.id, "product_uom": self.product_uom.id or self.product_id.uom_id.id, @@ -71,6 +71,9 @@ def _prepare_repair_stock_move(self): "origin": self.name, "company_id": self.company_id.id, } + if self.lot_id: + vals["restrict_lot_id"] = self.lot_id.id + return vals def _create_repair_stock_move(self): self.ensure_one() diff --git a/repair_stock_move/tests/test_repair_stock_move.py b/repair_stock_move/tests/test_repair_stock_move.py index 3b4634f9..d9a82b14 100644 --- a/repair_stock_move/tests/test_repair_stock_move.py +++ b/repair_stock_move/tests/test_repair_stock_move.py @@ -8,6 +8,9 @@ class TestRepairStockMove(common.TransactionCase): @classmethod def setUpClass(cls): super(TestRepairStockMove, cls).setUpClass() + # Models + cls.StockProductionLot = cls.env["stock.production.lot"] + cls.StockQuant = cls.env["stock.quant"] # Partners cls.res_partner_1 = cls.env["res.partner"].create({"name": "Wood Corner"}) cls.res_partner_address_1 = cls.env["res.partner"].create( @@ -104,6 +107,64 @@ def setUpClass(cls): cls.env.user.groups_id |= cls.env.ref("stock.group_stock_user") + # setup for the tests with lots + # we create several lots qith qty + # we want to check the system will get the correct lot + cls.product_lot = cls.env["product.product"].create( + { + "name": "Acoustic Magic Bloc", + "list_price": 2950.0, + "type": "product", + "tracking": "serial", + } + ) + cls.lot = cls.StockProductionLot.create( + { + "product_id": cls.product_lot.id, + "name": "Lot A", + "company_id": cls.env.company.id, + } + ) + cls.lot2 = cls.lot.copy({"name": "Lot B"}) + cls.lot3 = cls.lot.copy({"name": "Lot C"}) + cls.stock_location_stock = cls.env.ref("stock.stock_location_stock") + cls.StockQuant.create( + { + "location_id": cls.stock_location_stock.id, + "product_id": cls.product_lot.id, + "lot_id": cls.lot.id, + "inventory_quantity": 1, + } + ).action_apply_inventory() + cls.StockQuant.create( + { + "location_id": cls.stock_location_stock.id, + "product_id": cls.product_lot.id, + "lot_id": cls.lot2.id, + "inventory_quantity": 1, + } + ).action_apply_inventory() + cls.StockQuant.create( + { + "location_id": cls.stock_location_stock.id, + "product_id": cls.product_lot.id, + "lot_id": cls.lot3.id, + "inventory_quantity": 1, + } + ).action_apply_inventory() + cls.repair_with_lot = cls.env["repair.order"].create( + { + "invoice_method": "none", + "user_id": False, + "product_id": cls.product_lot.id, + "product_uom": cls.env.ref("uom.product_uom_unit").id, + "partner_invoice_id": cls.res_partner_address_1.id, + "location_id": cls.stock_location_stock.id, + "lot_id": cls.lot3.id, + "partner_id": cls.res_partner_12.id, + } + ) + def test_stock_move_state(self): # Validate Repair Order self.repair1.action_validate() @@ -177,14 +238,19 @@ def _create_simple_operation(self, repair_id=False, qty=0.0, price_unit=0.0): } ) - # def _create_simple_fee(self, repair_id=False, qty=0.0, price_unit=0.0): - # service = self.product_1 - # return self.env['repair.fee'].create({ - # 'name': 'PC Assemble + Custom (PC on Demand)', - # 'product_id': service.id, - # 'product_uom_qty': qty, - # 'product_uom': service.uom_id.id, - # 'price_unit': price_unit, - # 'repair_id': repair_id, - # 'company_id': self.env.company.id, - # }) + def test_stock_move_lot_reservation(self): + self.repair_with_lot.action_validate() + # Start Repair + self.repair_with_lot.action_repair_start() + # check stock move status and lot_id + for move in self.repair_with_lot.mapped("stock_move_ids"): + self.assertEqual( + move.state, + "assigned", + "Generated stock move state should be assigned", + ) + self.assertEqual( + move.move_line_ids.lot_id, + self.repair_with_lot.lot_id, + "Generated stock move lot_id should be the same as repair order", + )