Skip to content

Commit

Permalink
Modify channel name when the name of the company is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
louck committed Oct 9, 2024
1 parent a8c5181 commit f04bf77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions commown_b2b_mail_channel/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, models
from odoo import api, fields, models


class ResPartner(models.Model):
Expand Down Expand Up @@ -62,7 +62,7 @@ def create_mail_channel(self):
group_commercial = self.env.ref("commown_user_groups.commercial")
self.mail_channel_id = self.env["mail.channel"].create(
{
"name": " ".join(["Support", self.name]),
"name": self.compute_support_channel_name(),
"public": "private",
"company_id": self.id,
}
Expand All @@ -74,3 +74,11 @@ def create_mail_channel(self):
self.mail_channel_id.group_ids += (
group_admin + group_commercial + group_support
)

def compute_support_channel_name(self):
return " ".join(["Support", self.name])

@api.constrains("name")
def set_support_channel_name(self):
if self.mail_channel_id:
self.mail_channel_id.name = self.compute_support_channel_name()
15 changes: 15 additions & 0 deletions commown_b2b_mail_channel/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@ def test_channel_creation_on_active_contract_join_company(self):

self.part1.parent_id = self.company
self.assertTrue(self.company.mail_channel_id)

def test_set_support_channel_name(self):
self.company.create_mail_channel()
self.assertEqual(
self.company.mail_channel_id.name,
"Support %s" % self.company.name,
)

new_name = "New name"

self.company.name = new_name
self.assertEqual(
self.company.mail_channel_id.name,
"Support %s" % new_name,
)

0 comments on commit f04bf77

Please sign in to comment.