From 28f6e4ca42275298193ff0fa6699ea4328ef031f Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 11 Oct 2024 13:02:50 +0200 Subject: [PATCH 1/2] [REM] remove '|' in res company name --- joint_buying_base/models/res_company.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/joint_buying_base/models/res_company.py b/joint_buying_base/models/res_company.py index 21332d8b..2c5e6eb3 100644 --- a/joint_buying_base/models/res_company.py +++ b/joint_buying_base/models/res_company.py @@ -73,10 +73,9 @@ def _prepare_joint_buying_partner_vals(self): self.ensure_one() icp = self.env["ir.config_parameter"].sudo() group_name = icp.get_param("joint_buying_base.group_name", "") - suffix = group_name and ("(" + group_name + ")") or "" - sanitized_name = self.name.replace("|", "").strip() + suffix = group_name and (" (" + group_name + ")") or "" vals = { - "name": f"{sanitized_name} {suffix}", + "name": f"{self.name}{suffix}", "active": self.active, "is_joint_buying": True, "is_joint_buying_stage": True, From e331459eca2236fc250cabf1ac70850a092be3d6 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Sat, 19 Oct 2024 00:50:39 +0200 Subject: [PATCH 2/2] [IMP] joint_buying_base : Add company code in the name of the partner --- .../migrations/12.0.6.3.0/post-migration.py | 18 ++++++++++++++++++ joint_buying_base/models/res_company.py | 2 +- .../tests/test_company_2_partner.py | 9 ++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 joint_buying_base/migrations/12.0.6.3.0/post-migration.py diff --git a/joint_buying_base/migrations/12.0.6.3.0/post-migration.py b/joint_buying_base/migrations/12.0.6.3.0/post-migration.py new file mode 100644 index 00000000..f3693863 --- /dev/null +++ b/joint_buying_base/migrations/12.0.6.3.0/post-migration.py @@ -0,0 +1,18 @@ +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + ResCompany = env["res.company"].with_context(active_test=False) + companies = ResCompany.search([]) + for company in companies: + partner = company.joint_buying_partner_id.with_context( + write_joint_buying_partner=True + ) + new_name = company._prepare_joint_buying_partner_vals()["name"] + _logger.info(f"Rename {partner.name} into {new_name} ...") + partner.name = new_name diff --git a/joint_buying_base/models/res_company.py b/joint_buying_base/models/res_company.py index 2c5e6eb3..bfb41c48 100644 --- a/joint_buying_base/models/res_company.py +++ b/joint_buying_base/models/res_company.py @@ -73,7 +73,7 @@ def _prepare_joint_buying_partner_vals(self): self.ensure_one() icp = self.env["ir.config_parameter"].sudo() group_name = icp.get_param("joint_buying_base.group_name", "") - suffix = group_name and (" (" + group_name + ")") or "" + suffix = group_name and f" ({self.code} - {group_name})" or f"({self.code})" vals = { "name": f"{self.name}{suffix}", "active": self.active, diff --git a/joint_buying_base/tests/test_company_2_partner.py b/joint_buying_base/tests/test_company_2_partner.py index 50dff2ee..c61dd74d 100644 --- a/joint_buying_base/tests/test_company_2_partner.py +++ b/joint_buying_base/tests/test_company_2_partner.py @@ -18,11 +18,14 @@ def setUp(self): # Test Section def test_001_write_company_to_partner_info(self): company_name = "Demo Company for Joint Buying" - new_company = self.ResCompany.create({"name": company_name}) + company_code = "DJB" + new_company = self.ResCompany.create( + {"name": company_name, "code": company_code} + ) self.assertEqual( new_company.joint_buying_partner_id.name, - f"{company_name} ({self.suffixParameter.value})", + f"{company_name} ({company_code} - {self.suffixParameter.value})", "Create a company should create a related joint buying partner", ) @@ -46,6 +49,6 @@ def test_004_change_config_parameter(self): for company in self.ResCompany.search([]): self.assertEqual( company.joint_buying_partner_id.name, - f"{company.name} ({self.suffixParameter.value})", + f"{company.name} ({company.code} - {self.suffixParameter.value})", "Update the config parameter should update all the joint buying partner names", )