Skip to content

Commit

Permalink
Merge PR #88 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Jan 30, 2024
2 parents 5f32b39 + 8cfdf86 commit 3fd36f5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
34 changes: 31 additions & 3 deletions joint_buying_base/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -108,6 +109,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"
Expand All @@ -120,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(
Expand All @@ -130,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):
Expand All @@ -141,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)
1 change: 1 addition & 0 deletions joint_buying_base/tests/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
29 changes: 29 additions & 0 deletions joint_buying_base/tests/test_partner_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,32 @@ 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 set as 'Joint Buying Supplier'
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,
)

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,
)

0 comments on commit 3fd36f5

Please sign in to comment.