From a502c723bb362429878c8167a14136b53f9683f1 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Fri, 8 Oct 2021 17:15:14 +0200 Subject: [PATCH] [repair_refurbish][fix] Change destination location --- repair_refurbish/models/repair.py | 12 ++++++++++-- repair_refurbish/tests/test_repair_refurbish.py | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/repair_refurbish/models/repair.py b/repair_refurbish/models/repair.py index ffd04a66a..e76576287 100644 --- a/repair_refurbish/models/repair.py +++ b/repair_refurbish/models/repair.py @@ -103,8 +103,16 @@ class RepairLine(models.Model): and "to_refurbish" in context and not context["to_refurbish"] ): - scrap_location_id = self.env["stock.location"].search( - [("usage", "=", "customer")], limit=1 + scrap_location_id = ( + self.env["stock.location"] + .search( + [ + ("scrap_location", "=", True), + ("company_id", "in", [self.repair_id.company_id.id, False]), + ], + limit=1, + ) + .id ) self.location_dest_id = scrap_location_id return res diff --git a/repair_refurbish/tests/test_repair_refurbish.py b/repair_refurbish/tests/test_repair_refurbish.py index dd30e18b4..b05b4a00e 100644 --- a/repair_refurbish/tests/test_repair_refurbish.py +++ b/repair_refurbish/tests/test_repair_refurbish.py @@ -14,6 +14,9 @@ class TestMrpMtoWithStock(TransactionCase): self.stock_location_stock = self.env.ref("stock.stock_location_stock") self.customer_location = self.env.ref("stock.stock_location_customers") + self.scrap_location = self.env["stock.location"].search( + [("scrap_location", "=", True)], limit=1 + ) self.refurbish_loc = self.env.ref("repair_refurbish.stock_location_refurbish") self.refurbish_product = self.product_obj.create( @@ -159,4 +162,4 @@ class TestMrpMtoWithStock(TransactionCase): move = self.move_obj.search( [("product_id", "=", self.material2.id)], order="create_date desc", limit=1 )[0] - self.assertEqual(move.location_dest_id, self.customer_location) + self.assertEqual(move.location_dest_id, self.scrap_location)