From 638e0f658dc94960ca1d8abda9d1591de7f9a02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 7 Jul 2023 08:54:41 +0000 Subject: [PATCH] [REF] mail, various: cleanup alias usage Cleanup alias usage and definition. Prepare code to ease future changes and improvements. Notably * add a 'alias_email' computed field on the mixin allowing to have the complete alias email when set, and False in case it is inactive or linked to an inactive alias domain; * remove unnecessary alias_id field definition when just the help differs from the standard definition coming from the 'mail.alias.mixin'; * use fields coming from 'inherits' instead of using alias_id and its sub- fields; notably use 'alias_display_name' and 'alias_email' fields; * remove useless custom code and management; * improve alias parameters support code in configuration parameters; Task-3453343 (Mail: Cleanup Alias Usage) Prepares Task-36879 (Mail: Support MultiCompany Aliases) Part-of: odoo/odoo#130632 --- addons/crm/data/digest_data.xml | 6 +++--- addons/crm/models/crm_lead.py | 5 ++--- addons/crm/models/crm_team.py | 4 +--- addons/crm/tests/test_crm_lead.py | 2 +- .../crm/tests/test_crm_lead_multicompany.py | 2 +- addons/crm/views/crm_helper_templates.xml | 4 ++-- addons/hr_expense/models/hr_expense.py | 3 +-- addons/hr_recruitment/data/digest_data.xml | 4 ++-- addons/hr_recruitment/models/hr_applicant.py | 11 +++++----- addons/hr_recruitment/models/hr_job.py | 4 +--- .../models/hr_recruitment_source.py | 20 +++++++++---------- .../views/hr_recruitment_source_views.xml | 3 ++- .../mail/models/mail_alias_mixin_optional.py | 10 ++++++++++ addons/mail_group/__manifest__.py | 2 +- addons/mail_group/models/mail_group.py | 20 +++++-------------- addons/mail_group/views/mail_group_views.xml | 2 +- addons/mail_group/views/portal_templates.xml | 8 ++++---- addons/maintenance/models/maintenance.py | 4 +--- addons/project/__manifest__.py | 2 +- addons/project/data/digest_data.xml | 4 ++-- addons/project/models/project_project.py | 16 +++------------ .../project/views/project_project_views.xml | 8 ++++---- addons/test_mail/models/test_mail_models.py | 3 --- 23 files changed, 63 insertions(+), 84 deletions(-) diff --git a/addons/crm/data/digest_data.xml b/addons/crm/data/digest_data.xml index 9da9d78e512..d044815d18e 100644 --- a/addons/crm/data/digest_data.xml +++ b/addons/crm/data/digest_data.xml @@ -16,9 +16,9 @@

Tip: Convert incoming emails into opportunities

- -

Did you know emails sent to generate opportunities in your pipeline?
- Try sending an email to your CRM. This email address is configurable by sales team members.

+ +

Did you know emails sent to generate opportunities in your pipeline?
+ Try sending an email to your CRM. This email address is configurable by sales team members.

Did you know emails sent to a Sales Team alias generate opportunities in your pipeline?

diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 1bcea9ed084..d8c789384e1 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1276,10 +1276,9 @@ class Lead(models.Model): ('alias_force_thread_id', '=', False) ], limit=1) - if alias_record and alias_record.alias_domain and alias_record.alias_name: - email = f'{alias_record.alias_name}@{alias_record.alias_domain}' + if alias_record.alias_domain and alias_record.alias_name: sub_title = Markup(_('Use the New button, or send an email to %(email_link)s to test the email gateway.')) % { - 'email_link': Markup("%s") % (email, email), + 'email_link': Markup("%s") % (alias_record.display_name, alias_record.display_name), } return super().get_empty_list_help( f'

{help_title}

{sub_title}

' diff --git a/addons/crm/models/crm_team.py b/addons/crm/models/crm_team.py index 4ada6a3b3b2..40ccee93b3d 100644 --- a/addons/crm/models/crm_team.py +++ b/addons/crm/models/crm_team.py @@ -24,9 +24,7 @@ class Team(models.Model): use_leads = fields.Boolean('Leads', help="Check this box to filter and qualify incoming requests as leads before converting them into opportunities and assigning them to a salesperson.") use_opportunities = fields.Boolean('Pipeline', default=True, help="Check this box to manage a presales process with opportunities.") - alias_id = fields.Many2one( - 'mail.alias', string='Alias', ondelete="restrict", required=True, - help="The email address associated with this channel. New emails received will automatically create new leads assigned to the channel.") + alias_id = fields.Many2one(help="The email address associated with this channel. New emails received will automatically create new leads assigned to the channel.") # assignment assignment_enabled = fields.Boolean('Lead Assign', compute='_compute_assignment_enabled') assignment_auto_enabled = fields.Boolean('Auto Assignment', compute='_compute_assignment_enabled') diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py index 0b5e33f0492..8cf4b4a20f3 100644 --- a/addons/crm/tests/test_crm_lead.py +++ b/addons/crm/tests/test_crm_lead.py @@ -627,7 +627,7 @@ class TestCRMLead(TestCrmCommon): new_lead = self.format_and_process( INCOMING_EMAIL, 'unknown.sender@test.example.com', - '%s@%s' % (self.sales_team_1.alias_name, self.alias_domain), + self.sales_team_1.alias_email, subject='Delivery cost inquiry', target_model='crm.lead', ) diff --git a/addons/crm/tests/test_crm_lead_multicompany.py b/addons/crm/tests/test_crm_lead_multicompany.py index 7b6118d5b3a..ff1d57f9544 100644 --- a/addons/crm/tests/test_crm_lead_multicompany.py +++ b/addons/crm/tests/test_crm_lead_multicompany.py @@ -314,7 +314,7 @@ class TestCRMLeadMultiCompany(TestCrmCommon): new_lead = self.format_and_process( INCOMING_EMAIL, customer_company.email, - '%s@%s' % (self.sales_team_1.alias_name, self.alias_domain), + self.sales_team_1.alias_email, subject='Team having partner in company', target_model='crm.lead', ) diff --git a/addons/crm/views/crm_helper_templates.xml b/addons/crm/views/crm_helper_templates.xml index f3610e25e58..6cd44f01253 100644 --- a/addons/crm/views/crm_helper_templates.xml +++ b/addons/crm/views/crm_helper_templates.xml @@ -1,11 +1,11 @@