diff --git a/addons/crm/models/res_config_settings.py b/addons/crm/models/res_config_settings.py index 258caf44d56..93c4d8d629d 100644 --- a/addons/crm/models/res_config_settings.py +++ b/addons/crm/models/res_config_settings.py @@ -101,6 +101,8 @@ class ResConfigSettings(models.TransientModel): if alias: alias.write({'alias_name': self.crm_alias_prefix}) else: - self.env['mail.alias'].with_context( - alias_model_name='crm.lead', - alias_parent_model_name='crm.team').create({'alias_name': self.crm_alias_prefix}) + self.env['mail.alias'].create({ + 'alias_name': self.crm_alias_prefix, + 'alias_model_id': self.env['ir.model']._get('crm.lead').id, + 'alias_parent_model_id': self.env['ir.model']._get('crm.team').id, + }) diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index b6ad0c0ff49..30318c51869 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -29,6 +29,8 @@ class RecruitmentSource(models.Model): for source in self: vals = { 'alias_parent_thread_id': source.job_id.id, + 'alias_model_id': self.env['ir.model']._get('hr.applicant').id, + 'alias_parent_model_id': self.env['ir.model']._get('hr.job').id, 'alias_name': "%s+%s" % (source.job_id.alias_name or source.job_id.name, source.name), 'alias_defaults': { 'job_id': source.job_id.id, @@ -37,7 +39,7 @@ class RecruitmentSource(models.Model): 'source_id': source.source_id.id, }, } - source.alias_id = self.with_context(alias_model_name='hr.applicant', alias_parent_model_name='hr.job').env['mail.alias'].create(vals) + source.alias_id = self.env['mail.alias'].create(vals) source.name = source.source_id.name diff --git a/addons/mail/models/mail_alias_mixin.py b/addons/mail/models/mail_alias_mixin.py index 0a14346f479..58583b00e5b 100644 --- a/addons/mail/models/mail_alias_mixin.py +++ b/addons/mail/models/mail_alias_mixin.py @@ -19,19 +19,9 @@ class AliasMixin(models.AbstractModel): alias_id = fields.Many2one('mail.alias', string='Alias', ondelete="restrict", required=True) - def get_alias_model_name(self, vals): - """ Return the model name for the alias. Incoming emails that are not - replies to existing records will cause the creation of a new record - of this alias model. The value may depend on ``vals``, the dict of - values passed to ``create`` when a record of this model is created. - """ - return None - - def get_alias_values(self): - """ Return values to create an alias, or to write on the alias after its - creation. - """ - return {'alias_parent_thread_id': self.id} + # -------------------------------------------------- + # CRUD + # -------------------------------------------------- @api.model def create(self, vals): @@ -79,6 +69,28 @@ class AliasMixin(models.AbstractModel): _logger.info('Mail alias created for %s %s (id %s)', record._name, record.display_name, record.id) + # -------------------------------------------------- + # MIXIN TOOL OVERRIDE METHODS + # -------------------------------------------------- + + def get_alias_model_name(self, vals): + """ Return the model name for the alias. Incoming emails that are not + replies to existing records will cause the creation of a new record + of this alias model. The value may depend on ``vals``, the dict of + values passed to ``create`` when a record of this model is created. + """ + return None + + def get_alias_values(self): + """ Return values to create an alias, or to write on the alias after its + creation. + """ + return {'alias_parent_thread_id': self.id} + + # -------------------------------------------------- + # GATEWAY + # -------------------------------------------------- + def _alias_check_contact(self, message, message_dict, alias): """ Main mixin method that inheriting models may inherit in order to implement a specifc behavior. """