diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-05-23 10:09:35 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-12 14:54:11 +0000 |
| commit | bdebcab0cea467e070c1936fed16173247abafdd (patch) | |
| tree | fab225a6f198dd49cd65f22fbbbda8e6c5ee44ab /addons/phone_validation/tools/phone_validation.py | |
| parent | 488a5d5af5418ed5c223af5b61aea0b3100508c1 (diff) | |
[REF] sms: refactor message_post using SMS notifications
Purpose of this commit is to better include SMS notifications when posting a
message. SMS is now just another way of notifying people along with Inbox and
email. Following recent mail merge improving notification mechanism [1] we
have to define a _notify_record_by_sms method on mail.thread.
When a message_post is done using message_type being ``sms`` notification type
of customers is set to sms. Customers can be computed on model (generally based
on partner_id field) or directly set usign partner°ids. Notification model is
updated to store this information directly inside the notification itself.
An new ``_message_sms`` helper method is introduced in SMS module allowing
to send messages using sms type and notification with a reduced parameters
number. It is just a shortcut to message_post, easier to use. Either it
computes default recipients on the record set, either it is based on given
partners and numbers to notify.
The following use cases are notably supported
* default computation: find customer, notify by sms;
* force recipients to notify by sms (partner_ids);
* give a set of numbers to notify by sms (sms_nubmers), not necessarily
linked to existing partners;
* force number / customer relationship independently of mobile number defined
on customer (for example when sending an SMS directly from a mobile field
on a lead linked to a customer);
Tests are updated accordingly. Performance tests are added in order to have
some insights on queries generated when sending SMS, like already done for
mail.thread alone.
Related to task 1922163
Linked to PR #33510
[1] see be2795513644f09f6b443f462bb67cc5a0762e8d: performance and notification code improvements
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
Co-Authored-By: Pierre Rousseau <pro@odoo.com>
Diffstat (limited to 'addons/phone_validation/tools/phone_validation.py')
| -rw-r--r-- | addons/phone_validation/tools/phone_validation.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/addons/phone_validation/tools/phone_validation.py b/addons/phone_validation/tools/phone_validation.py index 29828ffd739..e1df861ac8c 100644 --- a/addons/phone_validation/tools/phone_validation.py +++ b/addons/phone_validation/tools/phone_validation.py @@ -77,51 +77,43 @@ except ImportError: def phone_sanitize_numbers(numbers, country_code, country_phone_code, force_format='E164'): - valid, invalid, void_count = [], [], 0 + result = dict.fromkeys(numbers, False) for number in numbers: if not number: - void_count += 1 + result[number] = {'sanitized': False, 'code': 'empty', 'msg': False} continue try: sanitized = phone_format( number, country_code, country_phone_code, force_format=force_format, raise_exception=True) except Exception as e: - invalid.append(number) + result[number] = {'sanitized': False, 'code': 'invalid', 'msg': e} else: - valid.append(sanitized) - return valid, invalid, void_count + result[number] = {'sanitized': sanitized, 'code': False, 'msg': False} + return result -def phone_sanitize_numbers_w_record(numbers, country_code, country_phone_code, record, record_country_fname='country_id', force_format='E164'): - if not country_code or not country_phone_code: - country = False - if record and record_country_fname in record and record[record_country_fname]: +def phone_sanitize_numbers_w_record(numbers, record, country=False, record_country_fname='country_id', force_format='E164'): + if not country: + if record and hasattr(record, record_country_fname) and record[record_country_fname]: country = record[record_country_fname] elif record: country = record.env.company.country_id - if country: - country_code = country_code if country_code else country.code - country_phone_code = country_phone_code if country_phone_code else country.phone_code + country_code = country.code if country else None + country_phone_code = country.phone_code if country else None return phone_sanitize_numbers(numbers, country_code, country_phone_code, force_format=force_format) -def phone_sanitize_numbers_string_w_record(numbers_str, country_code, country_phone_code, record, record_country_fname='country_id', force_format='E164'): +def phone_sanitize_numbers_string_w_record(numbers_str, record, country=False, record_country_fname='country_id', force_format='E164'): found_numbers = [number.strip() for number in numbers_str.split(',')] - return phone_sanitize_numbers_w_record(found_numbers, country_code, country_phone_code, record, record_country_fname, force_format=force_format) + return phone_sanitize_numbers_w_record(found_numbers, record, country=country, record_country_fname=record_country_fname, force_format=force_format) def phone_get_sanitized_records_number(records, number_fname='mobile', country_fname='country_id', force_format='E164'): res = dict.fromkeys(records.ids, False) for record in records: number = record[number_fname] - valid, invalid, void_count = phone_sanitize_numbers_w_record([number], None, None, records, country_fname,force_format=force_format) - if valid: - res[record.id] = valid[0] - elif void_count: - res[record.id] = False - else: - res[record.id] = False + res[record.id] = phone_sanitize_numbers_w_record([number], records, record_country_fname=country_fname,force_format=force_format)[number]['sanitized'] return res |
