diff options
| author | Munaf Khan <mub@odoo.com> | 2021-01-27 09:47:08 +0000 |
|---|---|---|
| committer | Dharmraj Jhala <dja@odoo.com> | 2021-02-12 04:59:25 +0000 |
| commit | fe177e76f92c38216afb7c977d91dece856e6bf1 (patch) | |
| tree | 408329ea558ea3d7683fd226877f92f65ce238c5 /addons/crm/models | |
| parent | 8bd81014f317c693b915a38d1d4dec0c5e490f90 (diff) | |
[FIX] crm: prevent crash due to invalid system parameter
Right now, if someone changes the `crm.pls_start_date` system parameter
to something that is not valid, opening a settings gives you traceback.
This commit improves the behavior by making sure that the compute field on
settings page `predictive_lead_scoring_start_date` always contains a valid
date. For doing so, if the system parameter is not a valid date(or not set
or deleted), we set the above field to the date 8 days prior to current
date, and thus, when saving the settings, the system parameter is again
set with a valid date.
closes odoo/odoo#65985
Taskid: 2448248
X-original-commit: ead10c7e0a22ce65a88558cdfaa99198ac27e524
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/crm/models')
| -rw-r--r-- | addons/crm/models/res_config_settings.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/addons/crm/models/res_config_settings.py b/addons/crm/models/res_config_settings.py index f01f8ea93c1..66fbc7335ca 100644 --- a/addons/crm/models/res_config_settings.py +++ b/addons/crm/models/res_config_settings.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from datetime import timedelta + from odoo import api, fields, models @@ -67,7 +69,16 @@ class ResConfigSettings(models.TransientModel): """ As config_parameters does not accept Date field, we get the date back from the Char config field, to ease the configuration in config panel """ for setting in self: - setting.predictive_lead_scoring_start_date = fields.Date.to_date(setting.predictive_lead_scoring_start_date_str) + lead_scoring_start_date = setting.predictive_lead_scoring_start_date_str + # if config param is deleted / empty, set the date 8 days prior to current date + if not lead_scoring_start_date: + setting.predictive_lead_scoring_start_date = fields.Date.to_date(fields.Date.today() - timedelta(days=8)) + else: + try: + setting.predictive_lead_scoring_start_date = fields.Date.to_date(lead_scoring_start_date) + except ValueError: + # the config parameter is malformed, so set the date 8 days prior to current date + setting.predictive_lead_scoring_start_date = fields.Date.to_date(fields.Date.today() - timedelta(days=8)) def _inverse_pls_start_date_str(self): """ As config_parameters does not accept Date field, |
