From fac4d23ff9eee545133facd2cae2c07f694e28ca Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 22 Jan 2024 15:04:48 +0100 Subject: [PATCH 1/2] [FIX] joint_buying_base : create a new company flagged 'is_joint_buying_supplier' should generate subscription --- joint_buying_base/models/res_company.py | 9 +++++++++ joint_buying_base/tests/test_abstract.py | 1 + .../tests/test_partner_subscription.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/joint_buying_base/models/res_company.py b/joint_buying_base/models/res_company.py index 01db9f43..d781b58b 100644 --- a/joint_buying_base/models/res_company.py +++ b/joint_buying_base/models/res_company.py @@ -108,6 +108,15 @@ def create(self, vals): partner_vals["customer"] = vals.get("is_joint_buying_customer") if "is_joint_buying_supplier" in vals: partner_vals["supplier"] = vals.get("is_joint_buying_supplier") + partner_vals["joint_buying_subscribed_company_ids"] = [ + ( + 6, + False, + ResPartner.with_context( + joint_buying=True + )._default_joint_buying_subscribed_company_ids(), + ) + ] if "joint_buying_is_durable_storage" in vals: partner_vals["joint_buying_is_durable_storage"] = vals.get( "joint_buying_is_durable_storage" diff --git a/joint_buying_base/tests/test_abstract.py b/joint_buying_base/tests/test_abstract.py index e94eb8a3..d1e76dee 100644 --- a/joint_buying_base/tests/test_abstract.py +++ b/joint_buying_base/tests/test_abstract.py @@ -10,6 +10,7 @@ class TestAbstract(TransactionCase): def setUp(self): super().setUp() + self.ResCompany = self.env["res.company"] self.ResPartner = self.env["res.partner"].with_context( mail_create_nosubscribe=True ) diff --git a/joint_buying_base/tests/test_partner_subscription.py b/joint_buying_base/tests/test_partner_subscription.py index 528139ea..430bd97f 100644 --- a/joint_buying_base/tests/test_partner_subscription.py +++ b/joint_buying_base/tests/test_partner_subscription.py @@ -34,3 +34,20 @@ def test_502_create_partner_subscription_by_user(self): supplier.toggle_joint_buying_is_subscribed() self.assertFalse(supplier.joint_buying_is_subscribed) + + def test_503_create_supplier_company_generate_subscription(self): + # Set 1GG as auto subscribable + self.company_3PP.joint_buying_auto_subscribe = True + + # Create New company + new_company = self.ResCompany.create( + { + "name": "New Company", + "is_joint_buying_supplier": True, + } + ) + + self.assertIn( + new_company.joint_buying_partner_id, + self.company_3PP.joint_buying_subscribed_partner_ids, + ) From 8cfdf86f00424f19938db3cf27b5bd947d1a81ba Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 22 Jan 2024 15:46:30 +0100 Subject: [PATCH 2/2] [FIX] joint_buying_base : set an existing company as 'is_joint_buying_supplier' should generate subscription --- joint_buying_base/models/res_company.py | 25 ++++++++++++++++--- .../tests/test_partner_subscription.py | 14 ++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/joint_buying_base/models/res_company.py b/joint_buying_base/models/res_company.py index d781b58b..21332d8b 100644 --- a/joint_buying_base/models/res_company.py +++ b/joint_buying_base/models/res_company.py @@ -66,6 +66,7 @@ def _get_company_fields_for_joint_buying_partner(self): "partner_longitude", "logo", "vat", + "is_joint_buying_supplier", ) def _prepare_joint_buying_partner_vals(self): @@ -129,6 +130,7 @@ def create(self, vals): @api.multi def write(self, vals): + ResPartner = self.env["res.partner"] # Technical Note: we add context key here # to avoid error when recomputing related / computed values res = super( @@ -139,7 +141,22 @@ def write(self, vals): ).write(vals) partner_fields = self._get_company_fields_for_joint_buying_partner() if list(set(vals.keys()) & set(partner_fields)): - self.update_joint_buying_partners() + extra_vals = {} + if vals.get("is_joint_buying_supplier", False): + extra_vals.update( + { + "joint_buying_subscribed_company_ids": [ + ( + 6, + False, + ResPartner.with_context( + joint_buying=True + )._default_joint_buying_subscribed_company_ids(), + ) + ] + } + ) + self.update_joint_buying_partners(extra_vals=extra_vals) return res def geo_localize(self): @@ -150,8 +167,10 @@ def geo_localize(self): return res @api.multi - def update_joint_buying_partners(self): + def update_joint_buying_partners(self, extra_vals=False): + extra_vals = extra_vals or {} for company in self: + extra_vals.update(company._prepare_joint_buying_partner_vals()) company.joint_buying_partner_id.with_context( write_joint_buying_partner=True - ).write(company._prepare_joint_buying_partner_vals()) + ).write(extra_vals) diff --git a/joint_buying_base/tests/test_partner_subscription.py b/joint_buying_base/tests/test_partner_subscription.py index 430bd97f..dfaacc49 100644 --- a/joint_buying_base/tests/test_partner_subscription.py +++ b/joint_buying_base/tests/test_partner_subscription.py @@ -39,7 +39,7 @@ def test_503_create_supplier_company_generate_subscription(self): # Set 1GG as auto subscribable self.company_3PP.joint_buying_auto_subscribe = True - # Create New company + # Create New company set as 'Joint Buying Supplier' new_company = self.ResCompany.create( { "name": "New Company", @@ -51,3 +51,15 @@ def test_503_create_supplier_company_generate_subscription(self): new_company.joint_buying_partner_id, self.company_3PP.joint_buying_subscribed_partner_ids, ) + + def test_504_update_supplier_company_generate_subscription(self): + # Set 1GG as autosubscribable + self.company_3PP.joint_buying_auto_subscribe = True + + # Set CDA as a supplier (was not before) + self.company_CDA.is_joint_buying_supplier = True + + self.assertIn( + self.company_CDA.joint_buying_partner_id, + self.company_3PP.joint_buying_subscribed_partner_ids, + )