summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-04-16 12:21:51 +0000
committerThibault Delavallée <tde@odoo.com>2020-04-17 06:51:39 +0000
commit4b3589359bd5bace5035eeeb6fd04ed29075cb1e (patch)
tree384110623c39072dc500eaf98ecc810a80a70b6f
parent4385ed024e9ce9bfa9f733c30cc163d2f10bfd60 (diff)
[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>
-rw-r--r--addons/crm/models/res_config_settings.py8
-rw-r--r--addons/hr_recruitment/models/hr_recruitment.py4
-rw-r--r--addons/mail/models/mail_alias_mixin.py38
3 files changed, 33 insertions, 17 deletions
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. """