summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2019-09-09 15:49:03 +0000
committerThibault Delavallée <tde@odoo.com>2019-09-09 15:54:45 +0000
commit4ba77c52f5d3287e7233eca604f2a086e3f29f7d (patch)
treeceedc5ffaea4ee91d285ecef0a20a8e7c6fcd713 /addons
parent5ed25aadb69d95c6335d0b2747d656823d4dec86 (diff)
[FIX] phone_validation: fix MRO issue with phone.validation.mixin
Issue is that when a model inherits from phone.Validation.mixin, then from mail.thread.phone (which inherits from phone.validation.mixin) we have an issue : TypeError: Cannot create a consistent method resolution order (MRO) for bases BaseModel, base, mail.thread, phone.validation.mixin, mail.thread.phone As fixing it could be complicated we have a way to avoid it: move conflicting code as it is used only in mail.thread.phone . In this commit we also import a file forgotten at d2809cbd941b20928cd1e48c50c1339888853d98 which triggers the issue itself. Task 2063049 (bug spotted) Task 2061765 (triggering the issue) closes odoo/odoo#36580 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/phone_validation/models/__init__.py1
-rw-r--r--addons/phone_validation/models/mail_thread_phone.py22
-rw-r--r--addons/phone_validation/models/phone_validation_mixin.py19
3 files changed, 22 insertions, 20 deletions
diff --git a/addons/phone_validation/models/__init__.py b/addons/phone_validation/models/__init__.py
index ba75abd0ddb..1402c4c2c28 100644
--- a/addons/phone_validation/models/__init__.py
+++ b/addons/phone_validation/models/__init__.py
@@ -4,3 +4,4 @@
from . import phone_blacklist
from . import phone_validation_mixin
from . import mail_thread_phone
+from . import res_partner
diff --git a/addons/phone_validation/models/mail_thread_phone.py b/addons/phone_validation/models/mail_thread_phone.py
index 3e166985f8e..f13161ad447 100644
--- a/addons/phone_validation/models/mail_thread_phone.py
+++ b/addons/phone_validation/models/mail_thread_phone.py
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
+from odoo.addons.phone_validation.tools import phone_validation
from odoo.exceptions import UserError
@@ -24,7 +25,7 @@ class PhoneMixin(models.AbstractModel):
"""
_name = 'mail.thread.phone'
_description = 'Phone Blacklist Mixin'
- _inherit = ['mail.thread', 'phone.validation.mixin']
+ _inherit = ['mail.thread']
phone_sanitized = fields.Char(
string='Sanitized Number', compute="_compute_phone_sanitized", compute_sudo=True, store=True,
@@ -96,6 +97,25 @@ class PhoneMixin(models.AbstractModel):
send an SMS on a record. """
return []
+ def _phone_get_country_field(self):
+ if 'country_id' in self:
+ return 'country_id'
+ return False
+
+ def phone_get_sanitized_numbers(self, number_fname='mobile', force_format='E164'):
+ res = dict.fromkeys(self.ids, False)
+ country_fname = self._phone_get_country_field()
+ for record in self:
+ number = record[number_fname]
+ res[record.id] = phone_validation.phone_sanitize_numbers_w_record([number], record, record_country_fname=country_fname, force_format=force_format)[number]['sanitized']
+ return res
+
+ def phone_get_sanitized_number(self, number_fname='mobile', force_format='E164'):
+ self.ensure_one()
+ country_fname = self._phone_get_country_field()
+ number = self[number_fname]
+ return phone_validation.phone_sanitize_numbers_w_record([number], self, record_country_fname=country_fname, force_format=force_format)[number]['sanitized']
+
def _phone_set_blacklisted(self):
return self.env['phone.blacklist'].sudo()._add([r.phone_sanitized for r in self])
diff --git a/addons/phone_validation/models/phone_validation_mixin.py b/addons/phone_validation/models/phone_validation_mixin.py
index 10eccb9b307..a430a537c21 100644
--- a/addons/phone_validation/models/phone_validation_mixin.py
+++ b/addons/phone_validation/models/phone_validation_mixin.py
@@ -9,11 +9,6 @@ class PhoneValidationMixin(models.AbstractModel):
_name = 'phone.validation.mixin'
_description = 'Phone Validation Mixin'
- def _phone_get_country_field(self):
- if 'country_id' in self:
- return 'country_id'
- return False
-
def _phone_get_country(self):
if 'country_id' in self and self.country_id:
return self.country_id
@@ -30,17 +25,3 @@ class PhoneValidationMixin(models.AbstractModel):
force_format='INTERNATIONAL',
raise_exception=False
)
-
- def phone_get_sanitized_numbers(self, number_fname='mobile', force_format='E164'):
- res = dict.fromkeys(self.ids, False)
- country_fname = self._phone_get_country_field()
- for record in self:
- number = record[number_fname]
- res[record.id] = phone_validation.phone_sanitize_numbers_w_record([number], record, record_country_fname=country_fname, force_format=force_format)[number]['sanitized']
- return res
-
- def phone_get_sanitized_number(self, number_fname='mobile', force_format='E164'):
- self.ensure_one()
- country_fname = self._phone_get_country_field()
- number = self[number_fname]
- return phone_validation.phone_sanitize_numbers_w_record([number], self, record_country_fname=country_fname, force_format=force_format)[number]['sanitized']