[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.
This commit is contained in:
Enrique 2020-01-02 13:45:13 +01:00 committed by Aungkokolin1997
parent 3316ab142a
commit d6cc4a8aa9
2 changed files with 14 additions and 17 deletions

View File

@ -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(

View File

@ -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