Skip to content

Commit 5996560

Browse files
committed
Merge PR #1037 into 16.0
Signed-off-by HviorForgeFlow
2 parents 22689d6 + a55de4e commit 5996560

5 files changed

Lines changed: 26 additions & 1 deletion

File tree

base_comment_template/models/base_comment_template.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BaseCommentTemplate(models.Model):
4242
help="If set, the comment template will be available only for the selected "
4343
"company.",
4444
)
45+
global_template = fields.Boolean()
4546
partner_ids = fields.Many2many(
4647
comodel_name="res.partner",
4748
relation="base_comment_template_res_partner_rel",

base_comment_template/models/comment_template.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def _compute_comment_template_ids(self):
4141
templates = template_model.search(
4242
expression.AND(
4343
[
44-
[("id", "in", partner.base_comment_template_ids.ids)],
44+
[
45+
"|",
46+
("id", "in", partner.base_comment_template_ids.ids),
47+
("global_template", "=", True),
48+
],
4549
template_domain,
4650
]
4751
)

base_comment_template/models/res_partner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ResPartner(models.Model):
1414
column1="res_partner_id",
1515
column2="base_comment_template_id",
1616
string="Comment Templates",
17+
domain=[("global_template", "=", False)],
1718
help="Specific partner comments that can be included in reports",
1819
)
1920

base_comment_template/tests/test_base_comment_template.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ def test_general_template(self):
8787
self.assertTrue(self.before_template_id in self.user.comment_template_ids)
8888
self.assertTrue(self.after_template_id in self.user.comment_template_ids)
8989

90+
def test_global_template(self):
91+
# Need to force _compute because only trigger when partner_id have changed
92+
global_template = self.env["base.comment.template"].create(
93+
{
94+
"name": "Top template",
95+
"text": "Text before lines",
96+
"models": self.user_obj.model,
97+
"company_id": self.company.id,
98+
}
99+
)
100+
self.user._compute_comment_template_ids()
101+
# Check getting default comment template
102+
self.assertNotIn(global_template, self.user.comment_template_ids)
103+
global_template.global_template = True
104+
self.user._compute_comment_template_ids()
105+
self.assertIn(global_template, self.user.comment_template_ids)
106+
90107
def test_partner_template(self):
91108
self.partner2_id.base_comment_template_ids = [
92109
(4, self.before_template_id.id),

base_comment_template/views/base_comment_template_view.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<field name="position" />
1111
<field name="company_id" groups="base.group_multi_company" />
1212
<field name="partner_ids" />
13+
<field name="global_template" />
1314
<field name="models" />
1415
<field name="model_ids" groups="base.group_erp_manager" />
1516
<field name="domain" />
@@ -71,6 +72,7 @@
7172
<field name="domain" />
7273
<field name="models" />
7374
<field name="partner_ids" widget="many2many_tags" />
75+
<field name="global_template" />
7476
<field name="engine" groups="base.group_no_one" />
7577
</group>
7678
</group>

0 commit comments

Comments
 (0)