[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, existing_policy=existing_policy,
) )
domain = self.env[ domain = self.env[
"mail.wizard.invite" 'mail.wizard.invite'
]._mail_restrict_follower_selection_get_domain() ]._mail_restrict_follower_selection_get_domain(res_model=res_model)
partners = self.env["res.partner"].search( partners = self.env['res.partner'].search(
[("id", "in", partner_ids)] + safe_eval(domain) [('id', 'in', partner_ids)] +
safe_eval(domain)
) )
_res_ids = res_ids.copy() or [0] _res_ids = res_ids.copy() or [0]
new, update = super()._add_followers( new, update = super()._add_followers(

View File

@ -11,19 +11,15 @@ class MailWizardInvite(models.TransientModel):
_inherit = "mail.wizard.invite" _inherit = "mail.wizard.invite"
@api.model @api.model
def _mail_restrict_follower_selection_get_domain(self): def _mail_restrict_follower_selection_get_domain(self, res_model=None):
parameter_name = "mail_restrict_follower_selection.domain" if not res_model:
return ( res_model = self.env.context.get('default_res_model')
self.env["ir.config_parameter"] parameter_name = 'mail_restrict_follower_selection.domain'
.sudo() return self.env['ir.config_parameter'].sudo().get_param(
.get_param( "{0}.{1}".format(parameter_name,
"{}.{}".format( res_model),
parameter_name, self.env.context.get("default_res_model") self.env['ir.config_parameter'].sudo().get_param(
), parameter_name, default='[]')
self.env["ir.config_parameter"]
.sudo()
.get_param(parameter_name, default="[]"),
)
) )
@api.model @api.model