From 0aeef6df96cbeb534aa234f5fc8c5803a5e53037 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Thu, 4 Aug 2022 10:17:17 +0200 Subject: [PATCH] [FIX] rma_put_away: fixes --- rma_put_away/models/rma_order_line.py | 3 -- rma_put_away/tests/test_rma_put_away.py | 54 +++++++++-------------- rma_put_away/wizards/rma_make_put_away.py | 4 +- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/rma_put_away/models/rma_order_line.py b/rma_put_away/models/rma_order_line.py index b74c8eeb..841c9106 100644 --- a/rma_put_away/models/rma_order_line.py +++ b/rma_put_away/models/rma_order_line.py @@ -103,9 +103,6 @@ class RmaOrderLine(models.Model): result = action.sudo().read()[0] pickings = self.env["stock.picking"] for line in self: - if line.lot_id: - line.move_ids.lot_ids |= line.lot_id - line.move_ids.move_line_ids.lot_id = line.lot_id pickings |= line.move_ids.filtered(lambda m: m.is_rma_put_away).mapped( "picking_id" ) diff --git a/rma_put_away/tests/test_rma_put_away.py b/rma_put_away/tests/test_rma_put_away.py index bfb6b901..b5c2df91 100644 --- a/rma_put_away/tests/test_rma_put_away.py +++ b/rma_put_away/tests/test_rma_put_away.py @@ -15,6 +15,7 @@ class TestRmaPutAway(common.SingleTransactionCase): cls.partner_obj = cls.env["res.partner"] cls.rma_route_cust = cls.env.ref("rma.route_rma_customer") + cls.cust_loc = cls.env.ref("stock.stock_location_customers") # Create customer cls.customer1 = cls.partner_obj.create({"name": "Customer 1"}) @@ -39,33 +40,12 @@ class TestRmaPutAway(common.SingleTransactionCase): "company_id": cls.env.ref("base.main_company").id, } ) - - cls.warehouse = cls.env["stock.warehouse"].create( - { - "name": "Warehouse", - "reception_steps": "one_step", - "delivery_steps": "ship_only", - "code": "WH1", - } - ) - - cls.warehouse_rma = cls.env["stock.warehouse"].create( - { - "name": "Warehouse RMA", - "reception_steps": "one_step", - "delivery_steps": "ship_only", - "code": "WH2", - } - ) - - cls.rma_loc = cls.env["stock.location"].create( - {"name": "WH RMA", "location_id": cls.warehouse_rma.view_location_id.id} - ) - + cls.wh = cls.env.ref("stock.warehouse0") + cls.stock_rma_location = cls.wh.lot_rma_id cls.put_away_loc = cls.env["stock.location"].create( { "name": "WH Put Away Location", - "location_id": cls.warehouse.view_location_id.id, + "location_id": cls.wh.view_location_id.id, } ) @@ -81,12 +61,12 @@ class TestRmaPutAway(common.SingleTransactionCase): { "name": "Transfer", "route_id": cls.route1.id, - "location_src_id": cls.rma_loc.id, + "location_src_id": cls.stock_rma_location.id, "location_id": cls.put_away_loc.id, "action": "pull", - "picking_type_id": cls.warehouse.int_type_id.id, + "picking_type_id": cls.wh.int_type_id.id, "procure_method": "make_to_stock", - "warehouse_id": cls.warehouse.id, + "warehouse_id": cls.wh.id, } ) @@ -132,7 +112,7 @@ class TestRmaPutAway(common.SingleTransactionCase): "out_route_id": self.operation_1.out_route_id.id, "in_warehouse_id": self.operation_1.in_warehouse_id.id, "out_warehouse_id": self.operation_1.out_warehouse_id.id, - "location_id": self.rma_loc.id, + "location_id": self.stock_rma_location.id, } ) rma._onchange_operation_id() @@ -167,7 +147,7 @@ class TestRmaPutAway(common.SingleTransactionCase): action = wizard.action_create_put_away() picking = self.env["stock.picking"].browse([action["res_id"]]) self.assertEqual(picking.location_dest_id.id, self.put_away_loc.id) - self.assertEqual(picking.location_id.id, self.rma_loc.id) + self.assertEqual(picking.location_id.id, self.stock_rma_location.id) move = picking.move_ids_without_package self.assertEqual(move.product_id.id, self.product_1.id) self.assertEqual(move.product_uom_qty, 1) @@ -176,7 +156,6 @@ class TestRmaPutAway(common.SingleTransactionCase): self.assertTrue(picking.button_validate()) def test_02_rma_put_away_with_lot(self): - """Generate a Sales Order from a customer RMA.""" rma = self.rma_line_obj.create( { "partner_id": self.customer1.id, @@ -188,7 +167,7 @@ class TestRmaPutAway(common.SingleTransactionCase): "out_route_id": self.operation_1.out_route_id.id, "in_warehouse_id": self.operation_1.in_warehouse_id.id, "out_warehouse_id": self.operation_1.out_warehouse_id.id, - "location_id": self.rma_loc.id, + "location_id": self.stock_rma_location.id, } ) rma._onchange_operation_id() @@ -202,7 +181,13 @@ class TestRmaPutAway(common.SingleTransactionCase): "active_id": 1, } ).create({}) - wizard._create_picking() + wizard.action_create_picking() + res = rma.action_view_in_shipments() + picking = self.env["stock.picking"].browse(res["res_id"]) + picking.action_assign() + for mv in picking.move_lines: + mv.quantity_done = mv.product_uom_qty + picking._action_done() wizard = self.rma_make_put_away_wiz.with_context( { "active_ids": rma.id, @@ -224,12 +209,13 @@ class TestRmaPutAway(common.SingleTransactionCase): ).create({}) action = wizard.action_create_put_away() picking = self.env["stock.picking"].browse([action["res_id"]]) + picking.action_assign() self.assertEqual(picking.location_dest_id.id, self.put_away_loc.id) - self.assertEqual(picking.location_id.id, self.rma_loc.id) + self.assertEqual(picking.location_id.id, self.stock_rma_location.id) move = picking.move_ids_without_package self.assertEqual(move.product_id.id, self.product_2.id) self.assertEqual(move.product_uom_qty, 1) - self.assertEqual(move.lot_ids.id, self.lot.id) + self.assertEqual(move.move_line_ids.lot_id.id, self.lot.id) move.quantity_done = 1 move.move_line_ids.lot_id = self.lot self.assertTrue(picking.button_validate()) diff --git a/rma_put_away/wizards/rma_make_put_away.py b/rma_put_away/wizards/rma_make_put_away.py index c5ceac7b..b67123c5 100644 --- a/rma_put_away/wizards/rma_make_put_away.py +++ b/rma_put_away/wizards/rma_make_put_away.py @@ -104,7 +104,9 @@ class RmaMakePutAway(models.TransientModel): def _prepare_procurement(self, item): line = item.line_id values = self._get_procurement_data(item) - 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.id, rma_id=item.line_id.rma_id.id + ) procurement = self.env["procurement.group"].Procurement( item.line_id.product_id, item.product_qty,