[IMP] phone_validation: improve default phone fields heuristic
RATIONALE Simplify field management for mail / phone / sms flows. Make it working out of the box, easier to use and tweak. SPECIFICATIONS Support by default 'phone' and 'mobile' fields if present on model as phone fields to fetch when searching for a number. This allows to remove several of unnecessary overrides always doing the same thing. Task-3422449 (Mail, Phone: Move and improve field helpers) Part-of: odoo/odoo#130468
This commit is contained in:
@@ -2040,10 +2040,6 @@ class Lead(models.Model):
|
||||
break
|
||||
return result
|
||||
|
||||
def _phone_get_number_fields(self):
|
||||
""" Use mobile or phone fields to compute sanitized phone number """
|
||||
return ['mobile', 'phone']
|
||||
|
||||
@api.model
|
||||
def get_import_templates(self):
|
||||
return [{
|
||||
|
||||
@@ -9,6 +9,3 @@ class MailingContact(models.Model):
|
||||
_inherit = ['mailing.contact', 'mail.thread.phone']
|
||||
|
||||
mobile = fields.Char(string='Mobile')
|
||||
|
||||
def _phone_get_number_fields(self):
|
||||
return ['mobile']
|
||||
|
||||
@@ -15,7 +15,9 @@ class BaseModel(models.AbstractModel):
|
||||
def _phone_get_number_fields(self):
|
||||
""" This method returns the fields to use to find the number to use to
|
||||
send an SMS on a record. """
|
||||
return []
|
||||
return [
|
||||
number_fname for number_fname in ('mobile', 'phone') if number_fname in self
|
||||
]
|
||||
|
||||
@api.model
|
||||
def _phone_get_country_field(self):
|
||||
|
||||
@@ -37,8 +37,3 @@ class Partner(models.Model):
|
||||
country_fname = 'country_id'
|
||||
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_get_number_fields(self):
|
||||
""" Stand alone version, allowing to use it on partner model without
|
||||
having any dependency on sms module. To cleanup in master (15.3 +)."""
|
||||
return ['mobile', 'phone']
|
||||
|
||||
@@ -13,8 +13,3 @@ class ResPartner(models.Model):
|
||||
SMS recipients on partners are the partners themselves.
|
||||
"""
|
||||
return self
|
||||
|
||||
def _phone_get_number_fields(self):
|
||||
""" This method returns the fields to use to find the number to use to
|
||||
send an SMS on a record. """
|
||||
return ['mobile', 'phone']
|
||||
|
||||
@@ -45,11 +45,6 @@ class Picking(models.Model):
|
||||
'context': self.env.context,
|
||||
}
|
||||
|
||||
def _sms_get_number_fields(self):
|
||||
""" No phone or mobile field is available on ``stock.picking`` model. Instead SMS will
|
||||
fallback on partner-based computation using ``_sms_get_partner_fields``. """
|
||||
return []
|
||||
|
||||
def _sms_get_partner_fields(self):
|
||||
return ['partner_id']
|
||||
|
||||
|
||||
@@ -90,6 +90,9 @@ class MailTestRating(models.Model):
|
||||
def _mail_get_partner_fields(self):
|
||||
return ['customer_id']
|
||||
|
||||
def _phone_get_number_fields(self):
|
||||
return ['phone_nbr', 'mobile_nbr']
|
||||
|
||||
def _rating_apply_get_default_subtype_id(self):
|
||||
return self.env['ir.model.data']._xmlid_to_res_id("test_mail_full.mt_mail_test_rating_rating_done")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user