summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2020-09-17 14:20:19 +0000
committerDavid Beguin <dbe@odoo.com>2020-09-21 17:33:08 +0000
commitcc4e7f401164acd053864a53372a96873d5d1b77 (patch)
treeff1da1af42cb0910bed860a7b7bccda31504b770
parent8bb3b09a2abf27011e4920a9dc045fc27e1ec628 (diff)
[FIX] crm: fix pls field config parameter and force depends recompute
The method _compute_probability has a dynamic depends, that depends on the crm.pls_fields config parameter. When installing the DB, the depends is evaluated. If the config parameter is modified afterwards, the depends is not re-evaluated as the registry is not rebuilt. The result is that when modifying the config parameter, if an optional pls_field's value is modified on a record, the compute won't be triggered, as that pls_field is not in the compute's depends. This commit force to re-setup the registry after a modification (or the creation) of the crm.pls_fields config parameter, in order to force the depends of the _compute_probability method to be updated. Task ID: 2341829 closes odoo/odoo#58163 X-original-commit: e95afbedc18d198454c7f66b523c4cafb19a4066 Signed-off-by: Raphael Collet (rco) <rco@openerp.com> Signed-off-by: David Beguin <dbeguin@users.noreply.github.com>
-rw-r--r--addons/crm/models/__init__.py1
-rw-r--r--addons/crm/models/ir_config_parameter.py23
-rw-r--r--addons/crm/tests/test_crm_pls.py9
3 files changed, 33 insertions, 0 deletions
diff --git a/addons/crm/models/__init__.py b/addons/crm/models/__init__.py
index 9d749786e6d..7b1a7fdcd7a 100644
--- a/addons/crm/models/__init__.py
+++ b/addons/crm/models/__init__.py
@@ -7,6 +7,7 @@ from . import crm_lead
from . import crm_lost_reason
from . import crm_stage
from . import crm_team
+from . import ir_config_parameter
from . import res_config_settings
from . import res_partner
from . import digest
diff --git a/addons/crm/models/ir_config_parameter.py b/addons/crm/models/ir_config_parameter.py
new file mode 100644
index 00000000000..890120a4974
--- /dev/null
+++ b/addons/crm/models/ir_config_parameter.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models
+
+
+class IrConfigParameter(models.Model):
+ _inherit = 'ir.config_parameter'
+
+ def write(self, vals):
+ result = super(IrConfigParameter, self).write(vals)
+ if any(record.key == "crm.pls_fields" for record in self):
+ self.flush()
+ self.env.registry.setup_models(self.env.cr)
+ return result
+
+ @api.model_create_multi
+ def create(self, vals_list):
+ records = super(IrConfigParameter, self).create(vals_list)
+ if any(record.key == "crm.pls_fields" for record in records):
+ self.flush()
+ self.env.registry.setup_models(self.env.cr)
+ return records
diff --git a/addons/crm/tests/test_crm_pls.py b/addons/crm/tests/test_crm_pls.py
index 9d74fac2938..b49e8e612d1 100644
--- a/addons/crm/tests/test_crm_pls.py
+++ b/addons/crm/tests/test_crm_pls.py
@@ -280,6 +280,15 @@ class TestCRMPLS(TransactionCase):
self.assertEqual(tools.float_compare(leads[3].probability, 40, 2), 0)
self.assertEqual(tools.float_compare(leads[8].probability, 2.43, 2), 0)
+ # Test modify country_id
+ leads[8].country_id = country_ids[1]
+ self.assertEqual(tools.float_compare(leads[8].automated_probability, 34.38, 2), 0)
+ self.assertEqual(tools.float_compare(leads[8].probability, 34.38, 2), 0)
+
+ leads[8].country_id = country_ids[0]
+ self.assertEqual(tools.float_compare(leads[8].automated_probability, 2.43, 2), 0)
+ self.assertEqual(tools.float_compare(leads[8].probability, 2.43, 2), 0)
+
# ----------------------------------------------
# Test tag_id frequencies and probability impact
# ----------------------------------------------