From ff0053b416958e89ef98bd97b7a50c1e371f7146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Mar 2017 16:45:02 +0100 Subject: [PATCH] [FIX] crm: fix behavior of 'Emails' checkbox in settings Currently there are several issues with this configuration box * default_ does not generate automatically ir.values anymore. Defining default_model does not work since it is not linked to an existing in current model sale.config.settings. Checkbox value is therefore not saved and lost at reload; * box label is not clear as user may understand unchecking it drops all aliases or email support. This is not the case as it is only used to define an alias creating unassigned leads. This is a rare use case where leads assignation is done manually; * checking / unchecking the 'Emails' box does not have any effect on default info alias. This is counter-intuitive as user asks to remove the feature but it still works in background; This commit fixes those issues by * correctly setting the checkbox value in an ir.config_parameter so that it is not lost anymore at reload; * inactivating info alias by default; * adding onchanges so that values are reset when unchecking checkboxes; * updating string and displayed label and helps for the 'Emails' section; * putting that Emails checkbox in advanced mode as it is a rare use case; --- addons/crm/data/crm_data.xml | 2 +- addons/crm/models/res_config.py | 23 ++++++++++++++++++++++- addons/crm/views/res_config_views.xml | 13 +++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/addons/crm/data/crm_data.xml b/addons/crm/data/crm_data.xml index 58249090f61..5121655ce49 100644 --- a/addons/crm/data/crm_data.xml +++ b/addons/crm/data/crm_data.xml @@ -10,7 +10,7 @@ - info + diff --git a/addons/crm/models/res_config.py b/addons/crm/models/res_config.py index a786f1e2c0b..b3bed2ba043 100644 --- a/addons/crm/models/res_config.py +++ b/addons/crm/models/res_config.py @@ -11,7 +11,8 @@ class CRMSettings(models.TransientModel): help="Odoo will generate an email alias based on the sales channel name") alias_prefix = fields.Char('Default Alias Name for Leads') alias_domain = fields.Char('Alias Domain', default=lambda self: self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain")) - default_generate_lead_from_alias = fields.Boolean() + # TDE TODO: as it is not linked to ir.values anymore, it should be renamed, but not in stable + default_generate_lead_from_alias = fields.Boolean('Manual Assignation of Emails') group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead') module_crm_voip = fields.Boolean("Asterisk (VoIP)") @@ -40,6 +41,26 @@ class CRMSettings(models.TransientModel): IrValues = IrValues.sudo() IrValues.set_default('sale.config.settings', 'generate_sales_team_alias', self.generate_sales_team_alias) + @api.model + def get_default_default_generate_lead_from_alias(self, fields): + return { + 'default_generate_lead_from_alias': self.env['ir.config_parameter'].sudo().get_param('sale_config_settings.default_generate_lead_from_alias') + } + + @api.multi + def set_default_default_generate_lead_from_alias(self): + self.env['ir.config_parameter'].sudo().set_param('sale_config_settings.default_generate_lead_from_alias', self.default_generate_lead_from_alias) + + @api.onchange('group_use_lead') + def _onchange_group_use_lead(self): + """ Reset alias / leads configuration if leads are not used """ + if not self.group_use_lead: + self.default_generate_lead_from_alias = False + + @api.onchange('default_generate_lead_from_alias') + def _onchange_default_generate_lead_from_alias(self): + self.alias_prefix = 'info' if self.default_generate_lead_from_alias else False + @api.model def get_default_alias_prefix(self, fields): alias = self._find_default_lead_alias_id() diff --git a/addons/crm/views/res_config_views.xml b/addons/crm/views/res_config_views.xml index 69df0c5a712..745b5e2b5ed 100644 --- a/addons/crm/views/res_config_views.xml +++ b/addons/crm/views/res_config_views.xml @@ -20,19 +20,24 @@ -
+
-