[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 d2809cbd94 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>
This commit is contained in:
Thibault Delavallée
2019-09-09 15:54:45 +00:00
parent 5ed25aadb6
commit 4ba77c52f5
3 changed files with 22 additions and 20 deletions
@@ -4,3 +4,4 @@
from . import phone_blacklist
from . import phone_validation_mixin
from . import mail_thread_phone
from . import res_partner
@@ -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])
@@ -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']