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 29, 2024
1 parent ff699f8 commit 8054c36
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 176 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 @@ -222,7 +222,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(

Check warning on line 226 in mrp_subcontracting_partner_management/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/models/res_partner.py#L225-L226

Added lines #L225 - L226 were not covered by tests
[("company_id", "=", company.id)], limit=1
)
picking_type = warehouse.out_type_id

Check warning on line 229 in mrp_subcontracting_partner_management/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/models/res_partner.py#L229

Added line #L229 was not covered by tests
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,154 +1,101 @@
from odoo.tests import common, tagged
from odoo.tools import mute_logger


@tagged("post_install", "-at_install")
class TestSubcontractedPartner(common.SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner_id = cls.env.ref("base.res_partner_12")
cls.partner_obj = cls.env["res.partner"]
cls.partner = cls.partner_obj.create({"name": "Test partner"})

def test_is_subcontractor_partner_first_time(self):
self.partner_id.update(
{
"is_subcontractor_partner": True,
}
)

location = self.partner_id.subcontracted_created_location_id
self.partner.update({"is_subcontractor_partner": True})
location = self.partner.subcontracted_created_location_id

Check warning on line 15 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L14-L15

Added lines #L14 - L15 were not covered by tests
self.assertTrue(location, "Location is not created")
self.assertTrue(location.active, "Location must be active")

partner_picking_type = self.partner_id.partner_picking_type_id
partner_picking_type = self.partner.partner_picking_type_id

Check warning on line 18 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L18

Added line #L18 was not covered by tests
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_id.partner_buy_rule_id
partner_buy_rule = self.partner.partner_buy_rule_id

Check warning on line 21 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L21

Added line #L21 was not covered by tests
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_id.partner_resupply_rule_id
partner_resupply_rule = self.partner.partner_resupply_rule_id

Check warning on line 24 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L24

Added line #L24 was not covered by tests
self.assertTrue(partner_resupply_rule, "Partner Resupply rule is not created")
self.assertTrue(
partner_resupply_rule.active, "Partner Resupply rule must be active"
)

def test_is_subcontractor_partner_switch_off(self):
self.partner_id.write(
{
"is_subcontractor_partner": True,
}
)
self.partner_id.update(
{
"is_subcontractor_partner": False,
}
)

location = self.partner_id.subcontracted_created_location_id
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_id.partner_picking_type_id
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_id.partner_buy_rule_id
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_id.partner_resupply_rule_id
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_id.update(
{
"is_subcontractor_partner": True,
}
)

location = self.partner_id.subcontracted_created_location_id
self.partner.update({"is_subcontractor_partner": True})
location = self.partner.subcontracted_created_location_id

Check warning on line 46 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L45-L46

Added lines #L45 - L46 were not covered by tests
self.assertTrue(location.active, "Location must be active")

partner_picking_type = self.partner_id.partner_picking_type_id
partner_picking_type = self.partner.partner_picking_type_id

Check warning on line 48 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L48

Added line #L48 was not covered by tests
self.assertTrue(partner_picking_type.active, "Picking type must be active")

partner_buy_rule = self.partner_id.partner_buy_rule_id
partner_buy_rule = self.partner.partner_buy_rule_id

Check warning on line 50 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L50

Added line #L50 was not covered by tests
self.assertTrue(partner_buy_rule.active, "Partner Buy rule must be active")

partner_resupply_rule = self.partner_id.partner_resupply_rule_id
partner_resupply_rule = self.partner.partner_resupply_rule_id

Check warning on line 52 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L52

Added line #L52 was not covered by tests
self.assertTrue(
partner_resupply_rule.active, "Partner Resupply rule must be active"
)

def test_is_subcontractor_partner_aсtive_switch_off(self):
self.partner_id.write(
{
"is_subcontractor_partner": True,
}
)
self.partner_id.update(
{
"active": False,
}
)

location = self.partner_id.subcontracted_created_location_id
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_id.partner_picking_type_id
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_id.partner_buy_rule_id
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_id.partner_resupply_rule_id
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_aсtive_switch_on(self):
self.partner_id.write(
{
"is_subcontractor_partner": True,
}
)
self.partner_id.write(
{
"active": True,
}
)

location = self.partner_id.subcontracted_created_location_id
self.partner.write({"is_subcontractor_partner": True})
self.partner.write({"active": True})
location = self.partner.subcontracted_created_location_id

Check warning on line 74 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L72-L74

Added lines #L72 - L74 were not covered by tests
self.assertTrue(location.active, "Location must be active")

partner_picking_type = self.partner_id.partner_picking_type_id
partner_picking_type = self.partner.partner_picking_type_id

Check warning on line 76 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L76

Added line #L76 was not covered by tests
self.assertTrue(partner_picking_type.active, "Picking type must be active")

partner_buy_rule = self.partner_id.partner_buy_rule_id
partner_buy_rule = self.partner.partner_buy_rule_id

Check warning on line 78 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L78

Added line #L78 was not covered by tests
self.assertTrue(partner_buy_rule.active, "Partner Buy rule must be active")

partner_resupply_rule = self.partner_id.partner_resupply_rule_id
partner_resupply_rule = self.partner.partner_resupply_rule_id

Check warning on line 80 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L80

Added line #L80 was not covered by tests
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_id = self.partner_obj.create(
partner = self.partner_obj.create(
{
"name": "Test partner",
"is_company": True,
"is_subcontractor_partner": True,
}
)

location = partner_id.subcontracted_created_location_id
partner_picking_type = partner_id.partner_picking_type_id
partner_buy_rule = partner_id.partner_buy_rule_id
partner_resupply_rule = partner_id.partner_resupply_rule_id

partner_id.unlink()

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 All @@ -157,15 +104,15 @@ def test_is_subcontractor_partner_delete(self):
)

def test_check_countof_rules(self):
partner_id = self.partner_obj.create(
partner = self.partner_obj.create(

Check warning on line 107 in mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_partner_management/tests/test_create_subcontractor_partner_location.py#L107

Added line #L107 was not covered by tests
{
"name": "Test partner",
"is_company": True,
"is_subcontractor_partner": True,
}
)
rules = self.env["stock.rule"].search(
[("name", "=", partner_id.partner_buy_rule_id.name)]
[("name", "=", partner.partner_buy_rule_id.name)]
)
self.assertTrue(len(rules) == 2, "There are must be 2 subcontractor rules")

Expand All @@ -184,7 +131,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 @@ -200,7 +146,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 All @@ -213,15 +158,15 @@ def test_change_subcontractor_location(self):
)

def test_action_subcontractor_location_stock(self):
self.partner_id.update({"is_subcontractor_partner": True})
action = self.partner_id.action_subcontractor_location_stock()
self.partner.update({"is_subcontractor_partner": True})
action = self.partner.action_subcontractor_location_stock()
self.assertEqual(
action.get("domain"),
[
(
"location_id",
"child_of",
self.partner_id.property_stock_subcontractor.ids,
self.partner.property_stock_subcontractor.ids,
)
],
msg="Domains must be the same",
Expand Down
Loading

0 comments on commit 8054c36

Please sign in to comment.