diff --git a/base_phone/README.rst b/base_phone/README.rst index 20be1f2..646db9d 100644 --- a/base_phone/README.rst +++ b/base_phone/README.rst @@ -81,6 +81,7 @@ Contributors ------------ * Alexis de Lattre +* Sébastien Beau Maintainer ---------- diff --git a/base_phone/__init__.py b/base_phone/__init__.py index 425df7e..c27d191 100644 --- a/base_phone/__init__.py +++ b/base_phone/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from . import base_phone +from . import fields +from . import models from . import wizard -from . import report_sxw_format -from . import controller diff --git a/base_phone/__openerp__.py b/base_phone/__openerp__.py index 6447c32..57a7943 100644 --- a/base_phone/__openerp__.py +++ b/base_phone/__openerp__.py @@ -33,9 +33,9 @@ 'data': [ 'security/phone_security.xml', 'security/ir.model.access.csv', - 'res_partner_view.xml', - 'res_company_view.xml', - 'res_users_view.xml', + 'views/res_partner_view.xml', + 'views/res_company_view.xml', + 'views/res_users_view.xml', 'wizard/reformat_all_phonenumbers_view.xml', 'wizard/number_not_found_view.xml', 'web_phone.xml', diff --git a/base_phone/base_phone.py b/base_phone/base_phone.py deleted file mode 100644 index d633ad9..0000000 --- a/base_phone/base_phone.py +++ /dev/null @@ -1,311 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Base Phone module for Odoo -# Copyright (C) 2010-2015 Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models, fields, api, _ -from openerp.tools.safe_eval import safe_eval -from openerp.exceptions import UserError -import logging -# Lib for phone number reformating -> pip install phonenumbers -import phonenumbers - -_logger = logging.getLogger(__name__) - - -class PhoneCommon(models.AbstractModel): - _name = 'phone.common' - - @api.model - def _reformat_phonenumbers_create(self, vals): - assert isinstance(self._phone_fields, list),\ - 'self._phone_fields must be a list' - if any([vals.get(field) for field in self._phone_fields]): - countrycode = self._get_countrycode_from_vals(vals) - countrycode = self._countrycode_fallback(countrycode) - vals = self._reformat_phonenumbers(vals, countrycode) - return vals - - @api.multi - def _reformat_phonenumbers_write(self, vals): - assert isinstance(self._phone_fields, list),\ - 'self._phone_fields must be a list' - if any([vals.get(field) for field in self._phone_fields]): - countrycode = self._get_countrycode_from_vals(vals) - if not countrycode: - if self._country_field: - country = safe_eval( - 'self.' + self._country_field, {'self': self}) - countrycode = country and country.code or None - elif self._partner_field: - partner = safe_eval( - 'self.' + self._partner_field, {'self': self}) - if partner: - countrycode = partner.country_id and\ - partner.country_id.code or None - - countrycode = self._countrycode_fallback(countrycode) - vals = self._reformat_phonenumbers(vals, countrycode) - return vals - - @api.model - def _get_countrycode_from_vals(self, vals): - assert isinstance(self._country_field, (str, unicode, type(None))),\ - 'Wrong self._country_field' - assert isinstance(self._partner_field, (str, unicode, type(None))),\ - 'Wrong self._partner_field' - countrycode = None - if self._country_field and vals.get(self._country_field): - # When updating a partner in the frontend of the POS - # Odoo generate a write() with the ID of the country as unicode !!! - # example : vals = {u'country_id': u'9'} - # So we have to convert it to an integer before browsing - country = self.env['res.country'].browse( - int(vals[self._country_field])) - countrycode = country.code - elif self._partner_field and vals.get(self._partner_field): - partner = self.env['res.partner'].browse( - vals[self._partner_field]) - countrycode = partner.country_id.code or False - return countrycode - - @api.model - def _countrycode_fallback(self, countrycode): - if not countrycode: - if self.env.user.company_id.country_id: - countrycode = self.env.user.company_id.country_id.code - else: - _logger.error( - "You should set a country on the company '%s' " - "to allow the reformat of phone numbers", - self.env.user.company_id.name) - return countrycode - - @api.model - def _reformat_phonenumbers(self, vals, countrycode): - for field in self._phone_fields: - if vals.get(field): - init_value = vals.get(field) - try: - res_parse = phonenumbers.parse( - vals.get(field), countrycode.upper()) - vals[field] = phonenumbers.format_number( - res_parse, phonenumbers.PhoneNumberFormat.E164) - if init_value != vals[field]: - _logger.info( - "%s initial value: '%s' updated value: '%s'" - % (field, init_value, vals[field])) - except Exception, e: - # I do BOTH logger and raise, because: - # raise is usefull when the record is created/written - # by a user via the Web interface - # logger is usefull when the record is created/written - # via the webservices - _logger.error( - "Cannot reformat the phone number '%s' to " - "international format with region=%s", - vals.get(field), countrycode) - if self.env.context.get('raise_if_phone_parse_fails'): - raise UserError( - _("Cannot reformat the phone number '%s' to " - "international format. Error message: %s") - % (vals.get(field), e)) - return vals - - @api.model - def get_name_from_phone_number(self, presented_number): - '''Function to get name from phone number. Usefull for use from IPBX - to add CallerID name to incoming calls.''' - res = self.get_record_from_phone_number(presented_number) - if res: - return res[2] - else: - return False - - @api.model - def get_record_from_phone_number(self, presented_number): - '''If it finds something, it returns (object name, ID, record name) - For example : ('res.partner', 42, u'Alexis de Lattre (Akretion)') - ''' - _logger.debug( - u"Call get_name_from_phone_number with number = %s" - % presented_number) - if not isinstance(presented_number, (str, unicode)): - _logger.warning( - u"Number '%s' should be a 'str' or 'unicode' but it is a '%s'" - % (presented_number, type(presented_number))) - return False - if not presented_number.isdigit(): - _logger.warning( - u"Number '%s' should only contain digits." % presented_number) - - nr_digits_to_match_from_end = \ - self.env.user.company_id.number_of_digits_to_match_from_end - if len(presented_number) >= nr_digits_to_match_from_end: - end_number_to_match = presented_number[ - -nr_digits_to_match_from_end:len(presented_number)] - else: - end_number_to_match = presented_number - - phoneobjects = self._get_phone_fields() - phonefieldslist = [] # [('res.parter', 10), ('crm.lead', 20)] - for objname in phoneobjects: - if ( - '_phone_name_sequence' in dir(self.env[objname]) and - self.env[objname]._phone_name_sequence): - phonefieldslist.append( - (objname, self.env[objname]._phone_name_sequence)) - phonefieldslist_sorted = sorted( - phonefieldslist, - key=lambda element: element[1]) - _logger.debug('phonefieldslist_sorted=%s' % phonefieldslist_sorted) - for (objname, prio) in phonefieldslist_sorted: - obj = self.with_context(callerid=True).env[objname] - pg_search_number = str('%' + end_number_to_match) - _logger.debug( - "Will search phone and mobile numbers in %s ending with '%s'" - % (objname, end_number_to_match)) - domain = [] - for phonefield in obj._phone_fields: - domain.append((phonefield, '=like', pg_search_number)) - if len(obj._phone_fields) > 1: - domain = ['|'] * (len(obj._phone_fields) - 1) + domain - res_obj = obj.search(domain) - if len(res_obj) > 1: - _logger.warning( - u"There are several %s (IDS = %s) with a phone number " - "ending with '%s'. Taking the first one." - % (objname, res_obj.ids, end_number_to_match)) - res_obj = res_obj[0] - if res_obj: - name = res_obj.name_get()[0][1] - res = (objname, res_obj.id, name) - _logger.debug( - u"Answer get_record_from_phone_number: (%s, %d, %s)" - % (res[0], res[1], res[2])) - return res - else: - _logger.debug( - u"No match on %s for end of phone number '%s'" - % (objname, end_number_to_match)) - return False - - @api.model - def _get_phone_fields(self): - '''Returns a dict with key = object name - and value = list of phone fields''' - models = self.env['ir.model'].search([('transient', '=', False)]) - res = [] - for model in models: - senv = False - try: - senv = self.env[model.model] - except: - continue - if ( - '_phone_fields' in dir(senv) and - isinstance(senv._phone_fields, list)): - res.append(model.model) - return res - - @api.model - def click2dial(self, erp_number): - '''This function is designed to be overridden in IPBX-specific - modules, such as asterisk_click2dial or ovh_telephony_connector''' - return {'dialed_number': erp_number} - - @api.model - def convert_to_dial_number(self, erp_number): - ''' - This function is dedicated to the transformation of the number - available in Odoo to the number that can be dialed. - You may have to inherit this function in another module specific - for your company if you are not happy with the way I reformat - the numbers. - ''' - assert(erp_number), 'Missing phone number' - _logger.debug('Number before reformat = %s' % erp_number) - # erp_number are supposed to be in E.164 format, so no need to - # give a country code here - parsed_num = phonenumbers.parse(erp_number, None) - country_code = self.env.user.company_id.country_id.code - assert(country_code), 'Missing country on company' - _logger.debug('Country code = %s' % country_code) - to_dial_number = phonenumbers.format_out_of_country_calling_number( - parsed_num, country_code.upper()) - to_dial_number = str(to_dial_number).translate(None, ' -.()/') - _logger.debug('Number to be sent to phone system: %s' % to_dial_number) - return to_dial_number - - -class ResPartner(models.Model): - _name = 'res.partner' - _inherit = ['res.partner', 'phone.common'] - _phone_fields = ['phone', 'mobile', 'fax'] - _phone_name_sequence = 10 - _country_field = 'country_id' - _partner_field = None - - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(ResPartner, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(ResPartner, self).write(vals_reformated) - - @api.multi - def name_get(self): - if self._context.get('callerid'): - res = [] - for partner in self: - if partner.parent_id and partner.parent_id.is_company: - name = u'%s (%s)' % (partner.name, partner.parent_id.name) - else: - name = partner.name - res.append((partner.id, name)) - return res - else: - return super(ResPartner, self).name_get() - - -class ResCompany(models.Model): - _inherit = 'res.company' - - number_of_digits_to_match_from_end = fields.Integer( - string='Number of Digits To Match From End', - default=8, - help="In several situations, OpenERP will have to find a " - "Partner/Lead/Employee/... from a phone number presented by the " - "calling party. As the phone numbers presented by your phone " - "operator may not always be displayed in a standard format, " - "the best method to find the related Partner/Lead/Employee/... " - "in OpenERP is to try to match the end of the phone number in " - "OpenERP with the N last digits of the phone number presented " - "by the calling party. N is the value you should enter in this " - "field.") - - _sql_constraints = [( - 'number_of_digits_to_match_from_end_positive', - 'CHECK (number_of_digits_to_match_from_end > 0)', - "The value of the field 'Number of Digits To Match From End' must " - "be positive."), - ] diff --git a/base_phone/fields.py b/base_phone/fields.py new file mode 100644 index 0000000..e90f843 --- /dev/null +++ b/base_phone/fields.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# Sébastien BEAU +# Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from openerp import api, fields, models +from operator import attrgetter +import phonenumbers +import logging + +_logger = logging.getLogger(__name__) + + +class Phone(fields.Char): + + _slots = { + 'country_field': None, + 'partner_field': None, + } + + def __init__( + self, string=None, country_field=None, partner_field=None, + **kwargs): + super(Phone, self).__init__( + string=string, country_field=country_field, + partner_field=partner_field, **kwargs) + + _related_country_field = property(attrgetter('country_field')) + _related_partner_field = property(attrgetter('partner_field')) + + def _setup_regular_full(self, model): + super(Phone, self)._setup_regular_full(model) + assert self.country_field in model._fields or \ + self.partner_field in model._fields, \ + "field %s with unknown country_field and partner_field" % self + + def convert_to_cache(self, value, record, validate=True): + res = super(Phone, self).convert_to_cache( + value, record, validate=validate) + # print 'db value', res + if res: + try: + res_parse = phonenumbers.parse(res) + res = phonenumbers.format_number( + res_parse, phonenumbers.PhoneNumberFormat.INTERNATIONAL) + # print "after parse+intl res=", res + except: + pass + # print 'cache value', res + return res + + +def convert_phone_field(value, country_code): + _logger.debug( + 'convert_phone_field value=%s country=%s', value, country_code) + try: + res_parse = phonenumbers.parse( + value, country_code) + _logger.debug('res_parse=%s', res_parse) + new_value = phonenumbers.format_number( + res_parse, phonenumbers.PhoneNumberFormat.E164) + _logger.debug('new_value=%s', new_value) + except: + _logger.error( + "Cannot reformat the phone number '%s' to " + "international format with region=%s", + value, country_code) + new_value = value + return new_value + + +def convert_all_phone_fields(self, vals, fields_to_convert): + loc_vals = vals.copy() + for field in fields_to_convert: + country_key = self._fields[field].country_field + partner_key = self._fields[field].partner_field + country = False + if country_key: + if country_key in loc_vals: + country = self.env['res.country'].browse(vals[country_key]) + else: + country = self[country_key] + elif partner_key: + if partner_key in loc_vals: + partner = self.env['res.partner'].browse(vals[partner_key]) + else: + partner = self[partner_key] + if partner: + country = partner.country_id + if not country: + country = self.env.user.company_id.country_id + country_code = False + if country: + country_code = country.code.upper() + loc_vals[field] = convert_phone_field(loc_vals[field], country_code) + return loc_vals + + +def get_phone_fields(self, vals): + fields_to_convert = [] + for key in vals: + if isinstance(self._fields[key], Phone): + fields_to_convert.append(key) + return fields_to_convert + +original_write = models.Model.write +original_create = models.Model.create + + +@api.multi +def write(self, vals): + fields_to_convert = get_phone_fields(self, vals) + if fields_to_convert: + for record in self: + loc_vals = convert_all_phone_fields( + record, vals, fields_to_convert) + original_write(record, loc_vals) + return True + else: + return original_write(self, vals) + + +@api.model +@api.returns('self', lambda value: value.id) +def create(self, vals): + fields_to_convert = get_phone_fields(self, vals) + if fields_to_convert: + vals = convert_all_phone_fields(self, vals, fields_to_convert) + return original_create(self, vals) + +models.Model.write = write +models.Model.create = create diff --git a/base_phone/models/__init__.py b/base_phone/models/__init__.py new file mode 100644 index 0000000..70636f6 --- /dev/null +++ b/base_phone/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +from . import controller +from . import res_company +from . import res_partner +from . import phone_common diff --git a/base_phone/controller.py b/base_phone/models/controller.py similarity index 100% rename from base_phone/controller.py rename to base_phone/models/controller.py diff --git a/base_phone/models/phone_common.py b/base_phone/models/phone_common.py new file mode 100644 index 0000000..8e992bc --- /dev/null +++ b/base_phone/models/phone_common.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- +# © 2010-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, api +from openerp.addons.base_phone.fields import Phone +import logging +# Lib for phone number reformating -> pip install phonenumbers +import phonenumbers + +_logger = logging.getLogger(__name__) + + +class PhoneCommon(models.AbstractModel): + _name = 'phone.common' + + @api.model + def get_name_from_phone_number(self, presented_number): + '''Function to get name from phone number. Usefull for use from IPBX + to add CallerID name to incoming calls.''' + res = self.get_record_from_phone_number(presented_number) + if res: + return res[2] + else: + return False + + @api.model + def get_record_from_phone_number(self, presented_number): + '''If it finds something, it returns (object name, ID, record name) + For example : ('res.partner', 42, u'Alexis de Lattre (Akretion)') + ''' + _logger.debug( + u"Call get_name_from_phone_number with number = %s" + % presented_number) + if not isinstance(presented_number, (str, unicode)): + _logger.warning( + u"Number '%s' should be a 'str' or 'unicode' but it is a '%s'" + % (presented_number, type(presented_number))) + return False + if not presented_number.isdigit(): + _logger.warning( + u"Number '%s' should only contain digits." % presented_number) + + nr_digits_to_match_from_end = \ + self.env.user.company_id.number_of_digits_to_match_from_end + if len(presented_number) >= nr_digits_to_match_from_end: + end_number_to_match = presented_number[ + -nr_digits_to_match_from_end:len(presented_number)] + else: + end_number_to_match = presented_number + + sorted_phonemodels = self._get_phone_models() + # [('res.parter', 10), ('crm.lead', 20)] + for (obj, prio) in sorted_phonemodels: + pg_search_number = str('%' + end_number_to_match) + _logger.debug( + "Will search phone and mobile numbers in %s ending with '%s'", + obj._name, end_number_to_match) + domain = [] + for field in obj._fields: + if isinstance(obj._fields[field], Phone): + domain.append((field, '=like', pg_search_number)) + if len(domain) > 1: + domain = ['|'] * (len(domain) - 1) + domain + _logger.debug('searching on %s with domain=%s', obj._name, domain) + res_obj = obj.search(domain) + if len(res_obj) > 1: + _logger.warning( + u"There are several %s (IDS = %s) with a phone number " + "ending with '%s'. Taking the first one.", + obj._name, res_obj.ids, end_number_to_match) + res_obj = res_obj[0] + if res_obj: + name = res_obj.name_get()[0][1] + res = (obj._name, res_obj.id, name) + _logger.debug( + u"Answer get_record_from_phone_number: (%s, %d, %s)", + res[0], res[1], res[2]) + return res + else: + _logger.debug( + u"No match on %s for end of phone number '%s'", + obj._name, end_number_to_match) + return False + + @api.model + def _get_phone_models(self): + res = [] + for model_name in self.env.registry.keys(): + senv = False + try: + senv = self.with_context(callerid=True).env[model_name] + except: + continue + if ( + hasattr(senv, '_phone_name_sequence') and + isinstance(senv._phone_name_sequence, int)): + res.append((senv, senv._phone_name_sequence)) + + phonemodels_sorted = sorted(res, key=lambda element: element[1]) + return phonemodels_sorted + + @api.model + def click2dial(self, erp_number): + '''This function is designed to be overridden in IPBX-specific + modules, such as asterisk_click2dial or ovh_telephony_connector''' + return {'dialed_number': erp_number} + + @api.model + def convert_to_dial_number(self, erp_number): + ''' + This function is dedicated to the transformation of the number + available in Odoo to the number that can be dialed. + You may have to inherit this function in another module specific + for your company if you are not happy with the way I reformat + the numbers. + ''' + assert(erp_number), 'Missing phone number' + _logger.debug('Number before reformat = %s' % erp_number) + # erp_number are supposed to be in E.164 format, so no need to + # give a country code here + parsed_num = phonenumbers.parse(erp_number, None) + country_code = self.env.user.company_id.country_id.code + assert(country_code), 'Missing country on company' + _logger.debug('Country code = %s' % country_code) + to_dial_number = phonenumbers.format_out_of_country_calling_number( + parsed_num, country_code.upper()) + to_dial_number = str(to_dial_number).translate(None, ' -.()/') + _logger.debug('Number to be sent to phone system: %s' % to_dial_number) + return to_dial_number diff --git a/base_phone/models/res_company.py b/base_phone/models/res_company.py new file mode 100644 index 0000000..ba4f9f0 --- /dev/null +++ b/base_phone/models/res_company.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + number_of_digits_to_match_from_end = fields.Integer( + string='Number of Digits To Match From End', + default=8, + help="In several situations, OpenERP will have to find a " + "Partner/Lead/Employee/... from a phone number presented by the " + "calling party. As the phone numbers presented by your phone " + "operator may not always be displayed in a standard format, " + "the best method to find the related Partner/Lead/Employee/... " + "in OpenERP is to try to match the end of the phone number in " + "OpenERP with the N last digits of the phone number presented " + "by the calling party. N is the value you should enter in this " + "field.") + + _sql_constraints = [( + 'number_of_digits_to_match_from_end_positive', + 'CHECK (number_of_digits_to_match_from_end > 0)', + "The value of the field 'Number of Digits To Match From End' must " + "be positive.")] diff --git a/base_phone/models/res_partner.py b/base_phone/models/res_partner.py new file mode 100644 index 0000000..5e71f91 --- /dev/null +++ b/base_phone/models/res_partner.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from openerp import models, api +from openerp.addons.base_phone import fields + + +class ResPartner(models.Model): + _inherit = 'res.partner' + _phone_name_sequence = 10 + + phone = fields.Phone(country_field='country_id', partner_field=None) + mobile = fields.Phone(country_field='country_id', partner_field=None) + fax = fields.Phone(country_field='country_id', partner_field=None) + + @api.multi + def name_get(self): + if self._context.get('callerid'): + res = [] + for partner in self: + if partner.parent_id and partner.parent_id.is_company: + name = u'%s (%s)' % (partner.name, partner.parent_id.name) + else: + name = partner.name + res.append((partner.id, name)) + return res + else: + return super(ResPartner, self).name_get() diff --git a/base_phone/report_sxw_format.py b/base_phone/report_sxw_format.py deleted file mode 100644 index 3ba94e6..0000000 --- a/base_phone/report_sxw_format.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Base Phone module for OpenERP -# Copyright (C) 2014 Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models -from openerp.report import report_sxw -import phonenumbers - - -class BasePhoneInstalled(models.AbstractModel): - '''When you use monkey patching, the code is executed when the module - is in the addons_path of the OpenERP server, even is the module is not - installed ! In order to avoid the side-effects it can create, - we create an AbstractModel inside the module and we test the - availability of this Model in the code of the monkey patching below. - At Akretion, we call this the "Guewen trick", in reference - to a trick used by Guewen Baconnier in the "connector" module. - ''' - _name = "base.phone.installed" - - -format_original = report_sxw.rml_parse.format - - -def format( - self, text, oldtag=None, phone=False, phone_format='international'): - if self.pool.get('base.phone.installed') and phone and text: - # text should already be in E164 format, so we don't have - # to give a country code to phonenumbers.parse() - phone_number = phonenumbers.parse(text) - if phone_format == 'international': - res = phonenumbers.format_number( - phone_number, phonenumbers.PhoneNumberFormat.INTERNATIONAL) - elif phone_format == 'national': - res = phonenumbers.format_number( - phone_number, phonenumbers.PhoneNumberFormat.NATIONAL) - elif phone_format == 'e164': - res = phonenumbers.format_number( - phone_number, phonenumbers.PhoneNumberFormat.E164) - else: - res = text - else: - res = format_original(self, text, oldtag=oldtag) - return res - -report_sxw.rml_parse.format = format diff --git a/base_phone/static/lib/phonenumbers/PhoneFormat.js b/base_phone/static/lib/phonenumbers/PhoneFormat.js deleted file mode 100644 index 889340b..0000000 --- a/base_phone/static/lib/phonenumbers/PhoneFormat.js +++ /dev/null @@ -1,1397 +0,0 @@ -/* - -Compiled Wednesday July 30, 2014 at 2:15pm America/New_York - -Version: libphonenumber r680 - ------------------------------------------------------------------------- - - - Copyright (C) Alan Beebe (alan.beebe@gmail.com). - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -Usage... - -This is the same type of code used by cell phones when you enter -a phone number into your dialer app. Your phone already knows -what country you are a subscriber in, so it assumes you are entering -a local number, unless of course you prefix the number with a +, or -in the USA you could also prefix the number with 011 to indicate you -wish to dial internationally. This code functions the same way. - -Lets assume your in the United States and you enter the following -phone number: 8646978257 - -formatE164("US", "8646978257"); - Returns: +18646978257 - -countryForE164Number("US", "+18646978257"); - Returns: US - -formatInternational("US", "8646978257"); - Returns: (864) 697-8257 - Info: This is the format you use if you are displaying this number to users outside the US - -formatLocal("US", "8646978257"); - Returns: (864) 697-8257 - Info: This is the format you use if you are displaying this number to users inside the US - (In certain countries, this format will be different then the international format) - -countryCodeToName("US"); - Returns: United States - - - -*/ - - -// ------------------------------------------------------------------------- -function countryForE164Number(phone) { - /* - - Return the country code for an e164 formatted number - - phone (String) phone number in e164 format to return the country code for - - */ - try { - var phone = cleanPhone(phone); - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var number = phoneUtil.parseAndKeepRawInput(phone); - var output = new goog.string.StringBuffer(); - output = phoneUtil.getRegionCodeForNumber(number); - return output.toString(); - } catch (e) { - return ""; - } -} - -// ------------------------------------------------------------------------- -function formatNumberForMobileDialing(country, phone) { - /* - - Returns a number formatted in such a way that it can be dialed from a mobile - phone in a specific region. If the number cannot be reached from the region - (e.g. some countries block toll-free numbers from being called outside of the - country), the method returns an empty string. - - */ - - try { - var phone = cleanPhone(phone); - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var number = phoneUtil.parseAndKeepRawInput(phone, country); - var output = new goog.string.StringBuffer(); - output = phoneUtil.formatNumberForMobileDialing(number, country, true); - return output.toString(); - } catch (e) { - return ""; - } -} - -// ------------------------------------------------------------------------- -function isValidNumber(phone, country) { - /* - - Tests whether a phone number matches a valid pattern. Note this doesn't - verify the number is actually in use, which is impossible to tell by just - looking at a number itself. - - */ - - try { - var phone = cleanPhone(phone); - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var number = phoneUtil.parseAndKeepRawInput(phone, country); - return phoneUtil.isValidNumber(number); - } catch (e) { - return false; - } -} - -// ------------------------------------------------------------------------- -function formatE164(country, phone) { - /* - - Return the phone number in e164 format - - country (String) 2 digit country code - phone (String) phone number to format - - */ - - try { - var phone = cleanPhone(phone); - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var number = phoneUtil.parseAndKeepRawInput(phone, country); - var PNF = i18n.phonenumbers.PhoneNumberFormat; - var output = new goog.string.StringBuffer(); - output = phoneUtil.format(number, PNF.E164); - return output.toString(); - } catch (e) { - return phone - } -} - - -// ------------------------------------------------------------------------- -function formatInternational(country, phone) { - /* - - Return the phone number in international format - - country (String) 2 digit country code - phone (String) phone number to format - - */ - - try { - var phone = cleanPhone(phone); - var formatter = new i18n.phonenumbers.AsYouTypeFormatter(country); - var output = new goog.string.StringBuffer(); - for (var i = 0; i < phone.length; ++i) { - var inputChar = phone.charAt(i); - output = (formatter.inputDigit(inputChar)); - } - return output.toString(); - } catch (e) { - return phone; - } -} - -// ------------------------------------------------------------------------- -function formatLocal(country, phone) { - /* - - Return the phone number in the format local to the user - - country (String) 2 digit country code - phone (String) phone number to format - - */ - - try { - var phone = cleanPhone(phone); - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var number = phoneUtil.parseAndKeepRawInput(phone, country); - if (phoneUtil.isValidNumberForRegion(number, country)) { - var PNF = i18n.phonenumbers.PhoneNumberFormat; - var output = new goog.string.StringBuffer(); - output = phoneUtil.format(number, PNF.NATIONAL); - return output.toString(); - } else { - return formatInternational(country, phone); - } - } catch (e) { - return formatInternational(country, phone); - } -} - -// ------------------------------------------------------------------------- -function exampleLandlineNumber(country) { - /* - - Returns an example land line phone number for the specified country - - country (String) 2 digit country code - - */ - - try { - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var output = phoneUtil.getExampleNumber(country); - return ""+output.getNationalNumber(); - } catch (e) { - return ""; - } -} - -// ------------------------------------------------------------------------- -function exampleMobileNumber(country) { - /* - - Returns an example mobile phone number for the specified country - - country (String) 2 digit country code - - */ - - try { - var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); - var output = phoneUtil.getExampleNumberForType(country, i18n.phonenumbers.PhoneNumberType.MOBILE); - return ""+output.getNationalNumber(); - } catch (e) { - return ""; - } -} - -// ------------------------------------------------------------------------- -function cleanPhone(phone) { - /* - - Remove any non numeric characters from the phone number but leave any plus sign at the beginning - - phone (String) phone number to clean - - */ - - phone = phone.replace(/[^\d\+]/g,''); - if (phone.substr(0, 1) == "+") { - phone = "+" + phone.replace(/[^\d]/g,''); - } else { - phone = phone.replace(/[^\d]/g,''); - } - return phone; -} - -// ------------------------------------------------------------------------- -function countryCodeToName(countryCode) { - /* - - Convert the country code to a name - - country (String) 2 digit country code - - */ - - var arrCountry = new Array(); - arrCountry['AF'] = "Afghanistan"; - arrCountry['AL'] = "Albania"; - arrCountry['DZ'] = "Algeria"; - arrCountry['AS'] = "American Samoa"; - arrCountry['AD'] = "Andorra"; - arrCountry['AO'] = "Angola"; - arrCountry['AI'] = "Anguilla"; - arrCountry['AQ'] = "Antarctica"; - arrCountry['AG'] = "Antigua And Barbuda"; - arrCountry['AR'] = "Argentina"; - arrCountry['AM'] = "Armenia"; - arrCountry['AW'] = "Aruba"; - arrCountry['AC'] = "Ascension Island"; - arrCountry['AU'] = "Australia"; - arrCountry['AT'] = "Austria"; - arrCountry['AZ'] = "Azerbaijan"; - arrCountry['BS'] = "Bahamas"; - arrCountry['BH'] = "Bahrain"; - arrCountry['BD'] = "Bangladesh"; - arrCountry['BB'] = "Barbados"; - arrCountry['BY'] = "Belarus"; - arrCountry['BE'] = "Belgium"; - arrCountry['BZ'] = "Belize"; - arrCountry['BJ'] = "Benin"; - arrCountry['BM'] = "Bermuda"; - arrCountry['BT'] = "Bhutan"; - arrCountry['BO'] = "Bolivia"; - arrCountry['BA'] = "Bosnia And Herzegovina"; - arrCountry['BW'] = "Botswana"; - arrCountry['BV'] = "Bouvet Island"; - arrCountry['BR'] = "Brazil"; - arrCountry['IO'] = "British Indian Ocean Territory"; - arrCountry['BN'] = "Brunei"; - arrCountry['BG'] = "Bulgaria"; - arrCountry['BF'] = "Burkina Faso"; - arrCountry['BI'] = "Burundi"; - arrCountry['KH'] = "Cambodia"; - arrCountry['CM'] = "Cameroon"; - arrCountry['CA'] = "Canada"; - arrCountry['CV'] = "Cape Verde"; - arrCountry['KY'] = "Cayman Islands"; - arrCountry['CF'] = "Central African Republic"; - arrCountry['TD'] = "Chad"; - arrCountry['CL'] = "Chile"; - arrCountry['CN'] = "China"; - arrCountry['CX'] = "Christmas Island"; - arrCountry['CC'] = "Cocos (Keeling) Islands"; - arrCountry['CO'] = "Columbia"; - arrCountry['KM'] = "Comoros"; - arrCountry['CG'] = "Congo"; - arrCountry['CK'] = "Cook Islands"; - arrCountry['CR'] = "Costa Rica"; - arrCountry['CI'] = "Cote D'Ivorie (Ivory Coast)"; - arrCountry['HR'] = "Croatia (Hrvatska)"; - arrCountry['CU'] = "Cuba"; - arrCountry['CY'] = "Cyprus"; - arrCountry['CZ'] = "Czech Republic"; - arrCountry['CD'] = "Democratic Republic Of Congo (Zaire)"; - arrCountry['DK'] = "Denmark"; - arrCountry['DJ'] = "Djibouti"; - arrCountry['DM'] = "Dominica"; - arrCountry['DO'] = "Dominican Republic"; - arrCountry['TL'] = "East Timor"; - arrCountry['EC'] = "Ecuador"; - arrCountry['EG'] = "Egypt"; - arrCountry['SV'] = "El Salvador"; - arrCountry['GQ'] = "Equatorial Guinea"; - arrCountry['ER'] = "Eritrea"; - arrCountry['EE'] = "Estonia"; - arrCountry['ET'] = "Ethiopia"; - arrCountry['FK'] = "Falkland Islands (Malvinas)"; - arrCountry['FO'] = "Faroe Islands"; - arrCountry['FJ'] = "Fiji"; - arrCountry['FI'] = "Finland"; - arrCountry['FR'] = "France"; - arrCountry['FX'] = "France, Metropolitan"; - arrCountry['GF'] = "French Guinea"; - arrCountry['PF'] = "French Polynesia"; - arrCountry['TF'] = "French Southern Territories"; - arrCountry['GA'] = "Gabon"; - arrCountry['GM'] = "Gambia"; - arrCountry['GE'] = "Georgia"; - arrCountry['DE'] = "Germany"; - arrCountry['GH'] = "Ghana"; - arrCountry['GI'] = "Gibraltar"; - arrCountry['GR'] = "Greece"; - arrCountry['GL'] = "Greenland"; - arrCountry['GD'] = "Grenada"; - arrCountry['GP'] = "Guadeloupe"; - arrCountry['GU'] = "Guam"; - arrCountry['GT'] = "Guatemala"; - arrCountry['GN'] = "Guinea"; - arrCountry['GW'] = "Guinea-Bissau"; - arrCountry['GY'] = "Guyana"; - arrCountry['HT'] = "Haiti"; - arrCountry['HM'] = "Heard And McDonald Islands"; - arrCountry['HN'] = "Honduras"; - arrCountry['HK'] = "Hong Kong"; - arrCountry['HU'] = "Hungary"; - arrCountry['IS'] = "Iceland"; - arrCountry['IN'] = "India"; - arrCountry['ID'] = "Indonesia"; - arrCountry['IR'] = "Iran"; - arrCountry['IQ'] = "Iraq"; - arrCountry['IE'] = "Ireland"; - arrCountry['IM'] = "Isle of Man"; - arrCountry['IL'] = "Israel"; - arrCountry['IT'] = "Italy"; - arrCountry['JM'] = "Jamaica"; - arrCountry['JP'] = "Japan"; - arrCountry['JO'] = "Jordan"; - arrCountry['KZ'] = "Kazakhstan"; - arrCountry['KE'] = "Kenya"; - arrCountry['KI'] = "Kiribati"; - arrCountry['KW'] = "Kuwait"; - arrCountry['KG'] = "Kyrgyzstan"; - arrCountry['LA'] = "Laos"; - arrCountry['LV'] = "Latvia"; - arrCountry['LB'] = "Lebanon"; - arrCountry['LS'] = "Lesotho"; - arrCountry['LR'] = "Liberia"; - arrCountry['LY'] = "Libya"; - arrCountry['LI'] = "Liechtenstein"; - arrCountry['LT'] = "Lithuania"; - arrCountry['LU'] = "Luxembourg"; - arrCountry['MO'] = "Macau"; - arrCountry['MK'] = "Macedonia"; - arrCountry['MG'] = "Madagascar"; - arrCountry['MW'] = "Malawi"; - arrCountry['MY'] = "Malaysia"; - arrCountry['MV'] = "Maldives"; - arrCountry['ML'] = "Mali"; - arrCountry['MT'] = "Malta"; - arrCountry['MH'] = "Marshall Islands"; - arrCountry['MQ'] = "Martinique"; - arrCountry['MR'] = "Mauritania"; - arrCountry['MU'] = "Mauritius"; - arrCountry['YT'] = "Mayotte"; - arrCountry['MX'] = "Mexico"; - arrCountry['FM'] = "Micronesia"; - arrCountry['MD'] = "Moldova"; - arrCountry['MC'] = "Monaco"; - arrCountry['MN'] = "Mongolia"; - arrCountry['ME'] = "Montenegro"; - arrCountry['MS'] = "Montserrat"; - arrCountry['MA'] = "Morocco"; - arrCountry['MZ'] = "Mozambique"; - arrCountry['MM'] = "Myanmar (Burma)"; - arrCountry['NA'] = "Namibia"; - arrCountry['NR'] = "Nauru"; - arrCountry['NP'] = "Nepal"; - arrCountry['NL'] = "Netherlands"; - arrCountry['AN'] = "Netherlands Antilles"; - arrCountry['NC'] = "New Caledonia"; - arrCountry['NZ'] = "New Zealand"; - arrCountry['NI'] = "Nicaragua"; - arrCountry['NE'] = "Niger"; - arrCountry['NG'] = "Nigeria"; - arrCountry['NU'] = "Niue"; - arrCountry['NF'] = "Norfolk Island"; - arrCountry['KP'] = "North Korea"; - arrCountry['MP'] = "Northern Mariana Islands"; - arrCountry['NO'] = "Norway"; - arrCountry['OM'] = "Oman"; - arrCountry['PK'] = "Pakistan"; - arrCountry['PW'] = "Palau"; - arrCountry['PS'] = "Palestine"; - arrCountry['PA'] = "Panama"; - arrCountry['PG'] = "Papua New Guinea"; - arrCountry['PY'] = "Paraguay"; - arrCountry['PE'] = "Peru"; - arrCountry['PH'] = "Philippines"; - arrCountry['PN'] = "Pitcairn"; - arrCountry['PL'] = "Poland"; - arrCountry['PT'] = "Portugal"; - arrCountry['PR'] = "Puerto Rico"; - arrCountry['QA'] = "Qatar"; - arrCountry['RE'] = "Reunion"; - arrCountry['RO'] = "Romania"; - arrCountry['RU'] = "Russia"; - arrCountry['RW'] = "Rwanda"; - arrCountry['SH'] = "Saint Helena"; - arrCountry['KN'] = "Saint Kitts And Nevis"; - arrCountry['LC'] = "Saint Lucia"; - arrCountry['PM'] = "Saint Pierre And Miquelon"; - arrCountry['VC'] = "Saint Vincent And The Grenadines"; - arrCountry['SM'] = "San Marino"; - arrCountry['ST'] = "Sao Tome And Principe"; - arrCountry['SA'] = "Saudi Arabia"; - arrCountry['SN'] = "Senegal"; - arrCountry['RS'] = "Serbia"; - arrCountry['SC'] = "Seychelles"; - arrCountry['SL'] = "Sierra Leone"; - arrCountry['SG'] = "Singapore"; - arrCountry['SK'] = "Slovak Republic"; - arrCountry['SI'] = "Slovenia"; - arrCountry['SB'] = "Solomon Islands"; - arrCountry['SO'] = "Somalia"; - arrCountry['ZA'] = "South Africa"; - arrCountry['GS'] = "South Georgia And South Sandwich Islands"; - arrCountry['KR'] = "South Korea"; - arrCountry['ES'] = "Spain"; - arrCountry['LK'] = "Sri Lanka"; - arrCountry['SD'] = "Sudan"; - arrCountry['SR'] = "Suriname"; - arrCountry['SJ'] = "Svalbard And Jan Mayen"; - arrCountry['SZ'] = "Swaziland"; - arrCountry['SE'] = "Sweden"; - arrCountry['CH'] = "Switzerland"; - arrCountry['SY'] = "Syria"; - arrCountry['TW'] = "Taiwan"; - arrCountry['TJ'] = "Tajikistan"; - arrCountry['TZ'] = "Tanzania"; - arrCountry['TH'] = "Thailand"; - arrCountry['TG'] = "Togo"; - arrCountry['TK'] = "Tokelau"; - arrCountry['TO'] = "Tonga"; - arrCountry['TT'] = "Trinidad And Tobago"; - arrCountry['TN'] = "Tunisia"; - arrCountry['TR'] = "Turkey"; - arrCountry['TM'] = "Turkmenistan"; - arrCountry['TC'] = "Turks And Caicos Islands"; - arrCountry['TV'] = "Tuvalu"; - arrCountry['UG'] = "Uganda"; - arrCountry['UA'] = "Ukraine"; - arrCountry['AE'] = "United Arab Emirates"; - arrCountry['GB'] = "United Kingdom"; - arrCountry['US'] = "United States"; - arrCountry['UM'] = "United States Minor Outlying Islands"; - arrCountry['UY'] = "Uruguay"; - arrCountry['UZ'] = "Uzbekistan"; - arrCountry['VU'] = "Vanuatu"; - arrCountry['VA'] = "Vatican City (Holy See)"; - arrCountry['VE'] = "Venezuela"; - arrCountry['VN'] = "Vietnam"; - arrCountry['VG'] = "Virgin Islands (British)"; - arrCountry['VI'] = "Virgin Islands (US)"; - arrCountry['WF'] = "Wallis And Futuna Islands"; - arrCountry['EH'] = "Western Sahara"; - arrCountry['WS'] = "Western Samoa"; - arrCountry['YE'] = "Yemen"; - arrCountry['YU'] = "Yugoslavia"; - arrCountry['ZM'] = "Zambia"; - arrCountry['ZW'] = "Zimbabwe"; - - var name = arrCountry[countryCode.toUpperCase()]; - if (name === undefined) { - return ""; - } else { - return name; - } -} - - -var COMPILED=!0,goog=goog||{};goog.global=this;goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c=c[d]?c[d]:c[d]={}:c[d]=b}; -goog.define=function(a,b){var c=b;COMPILED||(goog.global.CLOSURE_UNCOMPILED_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_UNCOMPILED_DEFINES,a)?c=goog.global.CLOSURE_UNCOMPILED_DEFINES[a]:goog.global.CLOSURE_DEFINES&&Object.prototype.hasOwnProperty.call(goog.global.CLOSURE_DEFINES,a)&&(c=goog.global.CLOSURE_DEFINES[a]));goog.exportPath_(a,c)};goog.DEBUG=!0;goog.LOCALE="en";goog.TRUSTED_SITE=!0;goog.STRICT_MODE_COMPATIBLE=!1; -goog.provide=function(a){if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a];for(var b=a;(b=b.substring(0,b.lastIndexOf(".")))&&!goog.getObjectByName(b);)goog.implicitNamespaces_[b]=!0}goog.exportPath_(a)};goog.setTestOnly=function(a){if(COMPILED&&!goog.DEBUG)throw a=a||"",Error("Importing test-only code into non-debug environment"+a?": "+a:".");};goog.forwardDeclare=function(a){}; -COMPILED||(goog.isProvided_=function(a){return!goog.implicitNamespaces_[a]&&goog.isDefAndNotNull(goog.getObjectByName(a))},goog.implicitNamespaces_={});goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]}; -goog.addDependency=function(a,b,c){if(goog.DEPENDENCIES_ENABLED){var d;a=a.replace(/\\/g,"/");for(var e=goog.dependencies_,f=0;d=b[f];f++)e.nameToPath[d]=a,a in e.pathToNames||(e.pathToNames[a]={}),e.pathToNames[a][d]=!0;for(d=0;b=c[d];d++)a in e.requires||(e.requires[a]={}),e.requires[a][b]=!0}};goog.ENABLE_DEBUG_LOADER=!0; -goog.require=function(a){if(!COMPILED&&!goog.isProvided_(a)){if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b){goog.included_[b]=!0;goog.writeScripts_();return}}a="goog.require could not find: "+a;goog.global.console&&goog.global.console.error(a);throw Error(a);}};goog.basePath="";goog.nullFunction=function(){};goog.identityFunction=function(a,b){return a};goog.abstractMethod=function(){throw Error("unimplemented abstract method");}; -goog.addSingletonGetter=function(a){a.getInstance=function(){if(a.instance_)return a.instance_;goog.DEBUG&&(goog.instantiatedSingletons_[goog.instantiatedSingletons_.length]=a);return a.instance_=new a}};goog.instantiatedSingletons_=[];goog.DEPENDENCIES_ENABLED=!COMPILED&&goog.ENABLE_DEBUG_LOADER; -goog.DEPENDENCIES_ENABLED&&(goog.included_={},goog.dependencies_={pathToNames:{},nameToPath:{},requires:{},visited:{},written:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return"undefined"!=typeof a&&"write"in a},goog.findBasePath_=function(){if(goog.global.CLOSURE_BASE_PATH)goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("script"),b=a.length-1;0<=b;--b){var c=a[b].src,d=c.lastIndexOf("?"),d=-1==d?c.length: -d;if("base.js"==c.substr(d-7,7)){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a){var b=goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_;!goog.dependencies_.written[a]&&b(a)&&(goog.dependencies_.written[a]=!0)},goog.writeScriptTag_=function(a){if(goog.inHtmlDocument_()){var b=goog.global.document;if("complete"==b.readyState){if(/\bdeps.js$/.test(a))return!1;throw Error('Cannot write "'+a+'" after document load');}b.write(' diff --git a/crm_claim_phone/__init__.py b/crm_claim_phone/__init__.py index 00c33a5..4ce1f5f 100644 --- a/crm_claim_phone/__init__.py +++ b/crm_claim_phone/__init__.py @@ -1,22 +1,3 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# CRM Claim Phone module for Odoo/OpenERP -# Copyright (C) 2014 Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## from . import crm_claim_phone diff --git a/crm_claim_phone/crm_claim_phone.py b/crm_claim_phone/crm_claim_phone.py index 5093964..9a60ae0 100644 --- a/crm_claim_phone/crm_claim_phone.py +++ b/crm_claim_phone/crm_claim_phone.py @@ -1,43 +1,12 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# CRM Claim Phone module for Odoo/OpenERP -# Copyright (c) 2012-2014 Akretion (http://www.akretion.com) -# @author: Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2012-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.osv import orm +from openerp import models +from openerp.addons.base_phone.fields import Phone -class crm_claim(orm.Model): - _name = 'crm.claim' - _inherit = ['crm.claim', 'phone.common'] - _phone_fields = ['partner_phone'] - _country_field = None - _partner_field = 'partner_id' +class CrmClaim(models.Model): + _inherit = 'crm.claim' - def create(self, cr, uid, vals, context=None): - vals_reformated = self._generic_reformat_phonenumbers( - cr, uid, None, vals, context=context) - return super(crm_claim, self).create( - cr, uid, vals_reformated, context=context) - - def write(self, cr, uid, ids, vals, context=None): - vals_reformated = self._generic_reformat_phonenumbers( - cr, uid, ids, vals, context=context) - return super(crm_claim, self).write( - cr, uid, ids, vals_reformated, context=context) + partner_phone = Phone(partner_field='partner_id') diff --git a/crm_claim_phone/crm_claim_view.xml b/crm_claim_phone/crm_claim_view.xml index 33e242a..3992163 100644 --- a/crm_claim_phone/crm_claim_view.xml +++ b/crm_claim_phone/crm_claim_view.xml @@ -1,11 +1,10 @@ - + @@ -20,4 +19,4 @@ - + diff --git a/crm_phone/crm_phone.py b/crm_phone/crm_phone.py index 53a3c40..380ee81 100644 --- a/crm_phone/crm_phone.py +++ b/crm_phone/crm_phone.py @@ -3,25 +3,21 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api, _ +from openerp.addons.base_phone.fields import Phone class CrmLead(models.Model): - _name = 'crm.lead' - _inherit = ['crm.lead', 'phone.common'] - _phone_fields = ['phone', 'mobile', 'fax'] + _inherit = 'crm.lead' _phone_name_sequence = 20 - _country_field = 'country_id' - _partner_field = None - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(CrmLead, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(CrmLead, self).write(vals_reformated) + phone = Phone(country_field='country_id') + mobile = Phone(country_field='country_id') + phone = Phone(country_field='country_id') + phonecall_ids = fields.One2many( + 'crm.phonecall', 'opportunity_id', string='Phone Calls') + phonecall_count = fields.Integer( + compute='_count_phonecalls', string='Number of Phonecalls', + readonly=True) @api.multi def name_get(self): @@ -41,12 +37,6 @@ class CrmLead(models.Model): else: return super(CrmLead, self).name_get() - phonecall_ids = fields.One2many( - 'crm.phonecall', 'opportunity_id', string='Phone Calls') - phonecall_count = fields.Integer( - compute='_count_phonecalls', string='Number of Phonecalls', - readonly=True) - @api.multi @api.depends('phonecall_ids') def _count_phonecalls(self): @@ -61,11 +51,8 @@ class CrmLead(models.Model): class CrmPhonecall(models.Model): _name = 'crm.phonecall' - _inherit = ['phone.common', 'mail.thread'] + _inherit = ['mail.thread'] _order = "id desc" - _phone_fields = ['partner_phone', 'partner_mobile'] - _country_field = None - _partner_field = 'partner_id' # Restore the object that existed in v8 # and doesn't exist in v9 community any more @@ -87,8 +74,8 @@ class CrmPhonecall(models.Model): default=lambda self: self.env['crm.team']._get_default_team_id()) partner_id = fields.Many2one( 'res.partner', string='Contact', ondelete='cascade') - partner_phone = fields.Char(string='Phone') - partner_mobile = fields.Char(string='Mobile') + partner_phone = Phone(string='Phone', partner_field='partner_id') + partner_mobile = Phone(string='Mobile', partner_field='partner_id') priority = fields.Selection([ ('0', 'Low'), ('1', 'Normal'), @@ -112,16 +99,6 @@ class CrmPhonecall(models.Model): ('outbound', 'Outbound'), ], string='Type', required=True, default='outbound') - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(CrmPhonecall, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(CrmPhonecall, self).write(vals_reformated) - @api.onchange('partner_id') def onchange_partner_id(self): if self.partner_id: diff --git a/event_phone/event_phone.py b/event_phone/event_phone.py index 624e4dd..c139f1a 100644 --- a/event_phone/event_phone.py +++ b/event_phone/event_phone.py @@ -2,23 +2,12 @@ # © 2012-2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, api +from openerp import models +from openerp.addons.base_phone.fields import Phone class EventRegistration(models.Model): - _name = 'event.registration' - _inherit = ['event.registration', 'phone.common'] - _phone_fields = ['phone'] + _inherit = 'event.registration' _phone_name_sequence = 100 - _country_field = None - _partner_field = 'partner_id' - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(EventRegistration, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(EventRegistration, self).write(vals_reformated) + phone = Phone(partner_field='partner_id') diff --git a/hr_phone/hr_phone.py b/hr_phone/hr_phone.py index 7ba0a83..23eb008 100644 --- a/hr_phone/hr_phone.py +++ b/hr_phone/hr_phone.py @@ -2,23 +2,13 @@ # © 2012-2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, api +from openerp import models +from openerp.addons.base_phone.fields import Phone class HrEmployee(models.Model): - _name = 'hr.employee' - _inherit = ['hr.employee', 'phone.common'] - _phone_fields = ['work_phone', 'mobile_phone'] + _inherit = 'hr.employee' _phone_name_sequence = 30 - _country_field = 'country_id' - _partner_field = None - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(HrEmployee, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(HrEmployee, self).write(vals_reformated) + work_phone = Phone(country_field='country_id') + mobile_phone = Phone(country_field='country_id') diff --git a/hr_recruitment_phone/hr_recruitment_phone.py b/hr_recruitment_phone/hr_recruitment_phone.py index 815c8ac..eae5b4b 100644 --- a/hr_recruitment_phone/hr_recruitment_phone.py +++ b/hr_recruitment_phone/hr_recruitment_phone.py @@ -3,25 +3,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, api +from openerp.addons.base_phone.fields import Phone class HrApplicant(models.Model): - _name = 'hr.applicant' - _inherit = ['hr.applicant', 'phone.common'] - _phone_fields = ['partner_phone', 'partner_mobile'] + _inherit = 'hr.applicant' _phone_name_sequence = 50 - _country_field = None - _partner_field = 'partner_id' - @api.model - def create(self, vals): - vals_reformated = self._reformat_phonenumbers_create(vals) - return super(HrApplicant, self).create(vals_reformated) - - @api.multi - def write(self, vals): - vals_reformated = self._reformat_phonenumbers_write(vals) - return super(HrApplicant, self).write(vals_reformated) + partner_phone = Phone(partner_field='partner_id') + partner_mobile = Phone(partner_field='partner_id') @api.multi def name_get(self):