[FIX] crm, hr_recruitment: clean manual alias creation
Purpose of this commit is to clean manual alias creation by correctly giving field values instead of relying on magic from model_name to model_id. Code is more understandable now. Task ID 1919277 Community PR odoo/odoo#41160 Enterprise PR odoo/enterprise#6983 Upgrade PR odoo/upgrade#872 Co-Authored-By: Rémy Voet <ryv@odoo.com> Co-Authored-By: Thibault Delavallée <tde@odoo.com>
This commit is contained in:
co-authored by
Rémy Voet
parent
4385ed024e
commit
4b3589359b
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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. """
|
||||
|
||||
Reference in New Issue
Block a user