-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP]hs_code_link: add tests to cover new changes
- Loading branch information
1 parent
1ed29a4
commit 85d71a1
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_hs_code_link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestHSCodeLink(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
# Models | ||
cls.company_model = cls.env["res.company"] | ||
cls.hs_code_model = cls.env["hs.code"] | ||
cls.product_template_model = cls.env["product.template"] | ||
cls.property_model = cls.env["ir.property"] | ||
|
||
# Instances | ||
cls.company_1 = cls._create_company("Company 1") | ||
cls.company_2 = cls._create_company("Company 2") | ||
|
||
cls.hs_code_1 = cls._create_hs_code() | ||
cls.hs_code_2 = cls._create_hs_code("12345678910") | ||
|
||
cls.product_template = cls._create_product_template("Product Template 1") | ||
|
||
@classmethod | ||
def _create_company(cls, name): | ||
return cls.company_model.create({"name": name}) | ||
|
||
@classmethod | ||
def _create_hs_code(cls, local_code="123456789", description=False): | ||
return cls.hs_code_model.with_context(skip_check_hs_code_heading=True).create( | ||
{"local_code": local_code, "description": description} | ||
) | ||
|
||
@classmethod | ||
def _create_product_template(cls, name): | ||
return cls.product_template_model.create({"name": name}) | ||
|
||
def test_01_check_correctly_sync_values_in_different_companies(self): | ||
""" | ||
Check that the values are correctly synced in different companies. | ||
""" | ||
# First Company | ||
template_company_1 = self.product_template.with_context( | ||
force_company=self.company_1.id | ||
) | ||
template_company_1.hs_code_id = self.hs_code_1 | ||
fields_to_sync = self.hs_code_model._get_fields_to_sync_from_hs_code_id() | ||
field_name = "hs_code" | ||
self.assertTrue( | ||
field_name | ||
in [hc_field_name for hc_field_name, _pt_field_name in fields_to_sync] | ||
) | ||
self.assertEqual( | ||
template_company_1.hs_code, | ||
self.hs_code_1.hs_code, | ||
"The H.S. Codes should be equal.", | ||
) | ||
# Second Company | ||
template_company_2 = self.product_template.with_context( | ||
force_company=self.company_2.id | ||
) | ||
template_company_2.hs_code_id = self.hs_code_2 | ||
self.assertEqual( | ||
template_company_2.hs_code, | ||
self.hs_code_2.hs_code, | ||
"The H.S. Codes should be equal.", | ||
) | ||
|
||
def test_02_delete_property(self): | ||
""" | ||
First create a Company Property and then delete it so check if the related | ||
Company Property is also deleted. | ||
""" | ||
template_company_1 = self.product_template.with_context( | ||
force_company=self.company_1.id | ||
) | ||
template_company_1.hs_code_id = self.hs_code_1 | ||
res_id = "product.template,%s" % template_company_1.id | ||
hs_code_id_property = self.property_model.search( | ||
[("res_id", "=", res_id), ("name", "=", "hs_code_id")], limit=1 | ||
) | ||
hs_code_property = self.property_model.search( | ||
[("res_id", "=", res_id), ("name", "=", "hs_code")], limit=1 | ||
) | ||
self.assertTrue(hs_code_id_property) | ||
self.assertTrue(hs_code_property) | ||
hs_code_id_property.unlink() | ||
self.assertFalse(hs_code_id_property.exists()) | ||
self.assertFalse(hs_code_property.exists()) |