Skip to content

Commit

Permalink
[FIX] mrp_subcontracting_partner_management: Define the correct picki…
Browse files Browse the repository at this point in the history
…ng_type (out) in the subcontracting_resupply rule

Before this change the picking_type_id used to create the subcontracting_resupply rule
was "fixed”, which is incorrect if you do not use the main company or multi-company.
  • Loading branch information
victoralmau committed Aug 30, 2024
1 parent ae0f56e commit cab5e88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
6 changes: 5 additions & 1 deletion mrp_subcontracting_partner_management/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo.tests import tagged
from odoo.tools import mute_logger

from odoo.addons.base.tests.common import BaseCommon

Expand All @@ -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(
Expand All @@ -34,33 +32,25 @@ 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"
)

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"
Expand All @@ -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"
Expand All @@ -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(
{
Expand All @@ -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")
Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand Down

0 comments on commit cab5e88

Please sign in to comment.