From d6cc4a8aa98be8a7d78a690de2f936375427a154 Mon Sep 17 00:00:00 2001 From: Enrique Date: Thu, 2 Jan 2020 13:45:13 +0100 Subject: [PATCH] [FIX] mail_restrict_follower_selection: res_model not always in context When creating a record from a record from another model, the model is not in the context (`default_res_model` key). For example: creating an invoice from a sale order. --- .../models/mail_followers.py | 9 ++++---- .../models/mail_wizard_invite.py | 22 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/mail_restrict_follower_selection/models/mail_followers.py b/mail_restrict_follower_selection/models/mail_followers.py index 06a9aaa..3576e15 100644 --- a/mail_restrict_follower_selection/models/mail_followers.py +++ b/mail_restrict_follower_selection/models/mail_followers.py @@ -35,10 +35,11 @@ class MailFollowers(models.Model): existing_policy=existing_policy, ) domain = self.env[ - "mail.wizard.invite" - ]._mail_restrict_follower_selection_get_domain() - partners = self.env["res.partner"].search( - [("id", "in", partner_ids)] + safe_eval(domain) + 'mail.wizard.invite' + ]._mail_restrict_follower_selection_get_domain(res_model=res_model) + partners = self.env['res.partner'].search( + [('id', 'in', partner_ids)] + + safe_eval(domain) ) _res_ids = res_ids.copy() or [0] new, update = super()._add_followers( diff --git a/mail_restrict_follower_selection/models/mail_wizard_invite.py b/mail_restrict_follower_selection/models/mail_wizard_invite.py index e04c486..0d579f7 100644 --- a/mail_restrict_follower_selection/models/mail_wizard_invite.py +++ b/mail_restrict_follower_selection/models/mail_wizard_invite.py @@ -11,19 +11,15 @@ class MailWizardInvite(models.TransientModel): _inherit = "mail.wizard.invite" @api.model - def _mail_restrict_follower_selection_get_domain(self): - parameter_name = "mail_restrict_follower_selection.domain" - return ( - self.env["ir.config_parameter"] - .sudo() - .get_param( - "{}.{}".format( - parameter_name, self.env.context.get("default_res_model") - ), - self.env["ir.config_parameter"] - .sudo() - .get_param(parameter_name, default="[]"), - ) + def _mail_restrict_follower_selection_get_domain(self, res_model=None): + if not res_model: + res_model = self.env.context.get('default_res_model') + parameter_name = 'mail_restrict_follower_selection.domain' + return self.env['ir.config_parameter'].sudo().get_param( + "{0}.{1}".format(parameter_name, + res_model), + self.env['ir.config_parameter'].sudo().get_param( + parameter_name, default='[]') ) @api.model