summaryrefslogtreecommitdiff
path: root/addons/phone_validation/models
diff options
context:
space:
mode:
authorDenis Ledoux <dle@odoo.com>2020-10-13 08:39:36 +0000
committerDenis Ledoux <dle@odoo.com>2020-10-13 08:39:36 +0000
commit55d7b9d3304f75aa2089c32c4a907066da4dc4b8 (patch)
tree65a0e9bcf320b8d83ecd480a7597d30c10ec633a /addons/phone_validation/models
parent36bb56a5e9704c76e84960ec84588524b52406f8 (diff)
[FIX] phone_validation: assign mobile_blacklisted and phone_blacklisted
Make sure to assign a value to the computed fields `mobile_blacklisted` and `phone_blacklisted` in their compute method for all record included in `self` Otherwise, not assigning a value for one record included in `self` can result in a cache missing error. ``` Traceback (most recent call last): File "/tmp/tmp3l14ain7/migrations/base/tests/test_mock_crawl.py", line 143, in crawl_menu self.mock_action(action_vals) File "/tmp/tmp3l14ain7/migrations/base/tests/test_mock_crawl.py", line 212, in mock_action mock_method(model, view, fields_list, domain, group_by) File "/tmp/tmp3l14ain7/migrations/base/tests/test_mock_crawl.py", line 238, in mock_view_form [data] = record.read(fields_list) File "/home/odoo/src/odoo/14.0/odoo/models.py", line 3001, in read return self._read_format(fnames=fields, load=load) File "/home/odoo/src/odoo/14.0/odoo/models.py", line 3021, in _read_format vals[name] = convert(record[name], record, use_name_get) File "/home/odoo/src/odoo/14.0/odoo/models.py", line 5620, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/home/odoo/src/odoo/14.0/odoo/fields.py", line 980, in __get__ raise ValueError("Compute method failed to assign %s.%s" % (record, self.name)) ValueError: Compute method failed to assign crm.lead(974,).phone_blacklisted ``` closes odoo/odoo#59827 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
Diffstat (limited to 'addons/phone_validation/models')
-rw-r--r--addons/phone_validation/models/mail_thread_phone.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/addons/phone_validation/models/mail_thread_phone.py b/addons/phone_validation/models/mail_thread_phone.py
index d560de1911a..7eacb84d5c6 100644
--- a/addons/phone_validation/models/mail_thread_phone.py
+++ b/addons/phone_validation/models/mail_thread_phone.py
@@ -63,15 +63,18 @@ class PhoneMixin(models.AbstractModel):
number_fields = self._phone_get_number_fields()
for record in self:
record.phone_sanitized_blacklisted = record.phone_sanitized in blacklist
+ mobile_blacklisted = phone_blacklisted = False
# This is a bit of a hack. Assume that any "mobile" numbers will have the word 'mobile'
# in them due to varying field names and assume all others are just "phone" numbers.
# Note that the limitation of only having 1 phone_sanitized value means that a phone/mobile number
# may not be calculated as blacklisted even though it is if both field values exist in a model.
for number_field in number_fields:
if 'mobile' in number_field:
- record.mobile_blacklisted = record.phone_sanitized_blacklisted and record.phone_get_sanitized_number(number_fname=number_field) == record.phone_sanitized
+ mobile_blacklisted = record.phone_sanitized_blacklisted and record.phone_get_sanitized_number(number_fname=number_field) == record.phone_sanitized
else:
- record.phone_blacklisted = record.phone_sanitized_blacklisted and record.phone_get_sanitized_number(number_fname=number_field) == record.phone_sanitized
+ phone_blacklisted = record.phone_sanitized_blacklisted and record.phone_get_sanitized_number(number_fname=number_field) == record.phone_sanitized
+ record.mobile_blacklisted = mobile_blacklisted
+ record.phone_blacklisted = phone_blacklisted
@api.model
def _search_phone_sanitized_blacklisted(self, operator, value):