[FIX] base_comment_template: search when multiple models in a template

pull/778/head
AaronHForgeFlow 2023-07-19 08:47:19 +02:00
parent 0115fe4b19
commit 89e980e61f
2 changed files with 5 additions and 3 deletions

View File

@ -120,6 +120,8 @@ class BaseCommentTemplate(models.Model):
def _search_model_ids(self, operator, value): def _search_model_ids(self, operator, value):
# We cannot use model_ids.model in search() method to avoid recursion. # We cannot use model_ids.model in search() method to avoid recursion.
allowed_items = ( allowed_items = (
self.sudo().search([]).filtered(lambda x: x.model_ids.model == value) self.sudo()
.search([])
.filtered(lambda x: value in x.model_ids.mapped("model"))
) )
return [("id", "in", allowed_items.ids)] return [("id", "in", allowed_items.ids)]

View File

@ -24,7 +24,7 @@ class CommentTemplate(models.AbstractModel):
compute_sudo=True, compute_sudo=True,
comodel_name="base.comment.template", comodel_name="base.comment.template",
string="Comment Template", string="Comment Template",
domain=lambda self: [("model_ids", "=", self._name)], domain=lambda self: [("model_ids", "in", self._name)],
store=True, store=True,
readonly=False, readonly=False,
) )
@ -32,7 +32,7 @@ class CommentTemplate(models.AbstractModel):
@api.depends(_comment_template_partner_field_name) @api.depends(_comment_template_partner_field_name)
def _compute_comment_template_ids(self): def _compute_comment_template_ids(self):
template_model = self.env["base.comment.template"] template_model = self.env["base.comment.template"]
template_domain = template_model._search_model_ids("=", self._name) template_domain = template_model._search_model_ids("in", self._name)
for record in self: for record in self:
partner = record[self._comment_template_partner_field_name] partner = record[self._comment_template_partner_field_name]
record.comment_template_ids = [(5,)] record.comment_template_ids = [(5,)]