diff --git a/mrp_subcontracting_partner_management/models/res_partner.py b/mrp_subcontracting_partner_management/models/res_partner.py index 58ac480f620..c0840ca40ba 100644 --- a/mrp_subcontracting_partner_management/models/res_partner.py +++ b/mrp_subcontracting_partner_management/models/res_partner.py @@ -207,7 +207,11 @@ def _create_route_rule_for_subcontracting_resupply(self, vals): prop = self.env["ir.property"]._get( "property_stock_production", "product.template" ) - picking_type = self.env.ref("stock.picking_type_out", raise_if_not_found=False) + company = self.company_id or self.env.company + warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", company.id)], limit=1 + ) + picking_type = warehouse.out_type_id route = self.env.ref( "mrp_subcontracting.route_resupply_subcontractor_mto", raise_if_not_found=False, diff --git a/mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py b/mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py index e45271b4df3..0d33a3cc450 100644 --- a/mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py +++ b/mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py @@ -1,4 +1,5 @@ from odoo.tests import tagged +from odoo.tools import mute_logger from odoo.addons.base.tests.common import BaseCommon @@ -16,15 +17,12 @@ def test_is_subcontractor_partner_first_time(self): location = self.partner.subcontracted_created_location_id self.assertTrue(location, "Location is not created") self.assertTrue(location.active, "Location must be active") - partner_picking_type = self.partner.partner_picking_type_id self.assertTrue(partner_picking_type, "Picking type is not created") self.assertTrue(partner_picking_type.active, "Picking type must be active") - partner_buy_rule = self.partner.partner_buy_rule_id self.assertTrue(partner_buy_rule, "Partner Buy rule is not created") self.assertTrue(partner_buy_rule.active, "Partner Buy rule must be active") - partner_resupply_rule = self.partner.partner_resupply_rule_id self.assertTrue(partner_resupply_rule, "Partner Resupply rule is not created") self.assertTrue( @@ -34,16 +32,12 @@ def test_is_subcontractor_partner_first_time(self): def test_is_subcontractor_partner_switch_off(self): self.partner.write({"is_subcontractor_partner": True}) self.partner.update({"is_subcontractor_partner": False}) - location = self.partner.subcontracted_created_location_id self.assertFalse(location.active, "Location must be not active") - partner_picking_type = self.partner.partner_picking_type_id self.assertFalse(partner_picking_type.active, "Picking type must be not active") - partner_buy_rule = self.partner.partner_buy_rule_id self.assertFalse(partner_buy_rule.active, "Partner Buy rule must be not active") - partner_resupply_rule = self.partner.partner_resupply_rule_id self.assertFalse( partner_resupply_rule.active, "Partner Resupply rule must be not active" @@ -51,16 +45,12 @@ def test_is_subcontractor_partner_switch_off(self): def test_is_subcontractor_partner_switch_on(self): self.partner.update({"is_subcontractor_partner": True}) - location = self.partner.subcontracted_created_location_id self.assertTrue(location.active, "Location must be active") - partner_picking_type = self.partner.partner_picking_type_id self.assertTrue(partner_picking_type.active, "Picking type must be active") - partner_buy_rule = self.partner.partner_buy_rule_id self.assertTrue(partner_buy_rule.active, "Partner Buy rule must be active") - partner_resupply_rule = self.partner.partner_resupply_rule_id self.assertTrue( partner_resupply_rule.active, "Partner Resupply rule must be active" @@ -69,16 +59,12 @@ def test_is_subcontractor_partner_switch_on(self): def test_is_subcontractor_partner_active_switch_off(self): self.partner.write({"is_subcontractor_partner": True}) self.partner.update({"active": False}) - location = self.partner.subcontracted_created_location_id self.assertFalse(location.active, "Location must be not active") - partner_picking_type = self.partner.partner_picking_type_id self.assertFalse(partner_picking_type.active, "Picking type must be not active") - partner_buy_rule = self.partner.partner_buy_rule_id self.assertFalse(partner_buy_rule.active, "Partner Buy rule must be not active") - partner_resupply_rule = self.partner.partner_resupply_rule_id self.assertFalse( partner_resupply_rule.active, "Partner Resupply rule must be not active" @@ -87,21 +73,18 @@ def test_is_subcontractor_partner_active_switch_off(self): def test_is_subcontractor_partner_aсtive_switch_on(self): self.partner.write({"is_subcontractor_partner": True}) self.partner.write({"active": True}) - location = self.partner.subcontracted_created_location_id self.assertTrue(location.active, "Location must be active") - partner_picking_type = self.partner.partner_picking_type_id self.assertTrue(partner_picking_type.active, "Picking type must be active") - partner_buy_rule = self.partner.partner_buy_rule_id self.assertTrue(partner_buy_rule.active, "Partner Buy rule must be active") - partner_resupply_rule = self.partner.partner_resupply_rule_id self.assertTrue( partner_resupply_rule.active, "Partner Resupply rule must be active" ) + @mute_logger("odoo.models.unlink") def test_is_subcontractor_partner_delete(self): partner = self.partner_obj.create( { @@ -110,14 +93,11 @@ def test_is_subcontractor_partner_delete(self): "is_subcontractor_partner": True, } ) - location = partner.subcontracted_created_location_id partner_picking_type = partner.partner_picking_type_id partner_buy_rule = partner.partner_buy_rule_id partner_resupply_rule = partner.partner_resupply_rule_id - partner.unlink() - self.assertFalse(location.active, "Location must be not active") self.assertFalse(partner_picking_type.active, "Picking type must be not active") self.assertFalse(partner_buy_rule.active, "Partner Buy rule must be not active") @@ -153,7 +133,6 @@ def test_change_subcontractor_location(self): expected_text, msg="Location name must be equal to {}".format(expected_text), ) - fields = [ "subcontracted_created_location_id", "partner_buy_rule_id", @@ -169,7 +148,6 @@ def test_change_subcontractor_location(self): expected_text, msg="Record name must be equal to {}".format(expected_text), ) - picking = partner.partner_picking_type_id expected_text = "%s: IN" % expected_text self.assertEqual(