From 31a0356f9d57d496e3d0213a0e170681fb775030 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Thu, 22 Nov 2012 11:06:52 -0500 Subject: [PATCH] [ADD] res_partner_address_formatted_phone [ADD] crm_lead_formatted_phone Needs rewriting to get regex from res.country and maybe use phonenumbers lib --- crm_lead_formatted_phone/__init__.py | 22 ++++++++++ crm_lead_formatted_phone/__openerp__.py | 41 +++++++++++++++++ .../crm_lead_formatted_phone.py | 39 ++++++++++++++++ .../crm_lead_formatted_phone.xml | 33 ++++++++++++++ .../__init__.py | 23 ++++++++++ .../__openerp__.py | 44 +++++++++++++++++++ .../res_country_phone_format.py | 31 +++++++++++++ .../res_country_phone_format_data.xml | 10 +++++ .../res_country_phone_format_view.xml | 18 ++++++++ .../res_partner_address_formatted_phone.py | 41 +++++++++++++++++ .../res_partner_address_formatted_phone.xml | 28 ++++++++++++ 11 files changed, 330 insertions(+) create mode 100644 crm_lead_formatted_phone/__init__.py create mode 100644 crm_lead_formatted_phone/__openerp__.py create mode 100644 crm_lead_formatted_phone/crm_lead_formatted_phone.py create mode 100644 crm_lead_formatted_phone/crm_lead_formatted_phone.xml create mode 100644 res_partner_address_formatted_phone/__init__.py create mode 100644 res_partner_address_formatted_phone/__openerp__.py create mode 100644 res_partner_address_formatted_phone/res_country_phone_format.py create mode 100644 res_partner_address_formatted_phone/res_country_phone_format_data.xml create mode 100644 res_partner_address_formatted_phone/res_country_phone_format_view.xml create mode 100644 res_partner_address_formatted_phone/res_partner_address_formatted_phone.py create mode 100644 res_partner_address_formatted_phone/res_partner_address_formatted_phone.xml diff --git a/crm_lead_formatted_phone/__init__.py b/crm_lead_formatted_phone/__init__.py new file mode 100644 index 000000000..b49fb557f --- /dev/null +++ b/crm_lead_formatted_phone/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +import crm_lead_formatted_phone diff --git a/crm_lead_formatted_phone/__openerp__.py b/crm_lead_formatted_phone/__openerp__.py new file mode 100644 index 000000000..433bf3681 --- /dev/null +++ b/crm_lead_formatted_phone/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +{ + "name" : "Format phone numbers of lead ", + "version" : "0.1", + "author" : "Savoir-faire Linux", + "website" : "http://www.savoirfairelinux.com", + "license" : "AGPL-3", + "category" : "CRM", + "description" : """ +This module formats the lead phone numbers based on the country phone format. + """, + "images" : [], + "depends" : ["crm", "res_partner_address_formatted_phone"], + "demo" : [], + "test" : [], + "data" : [ + "crm_lead_formatted_phone.xml", + ], + "installable": True, + "complexity": "easy", +} diff --git a/crm_lead_formatted_phone/crm_lead_formatted_phone.py b/crm_lead_formatted_phone/crm_lead_formatted_phone.py new file mode 100644 index 000000000..daacc1fb8 --- /dev/null +++ b/crm_lead_formatted_phone/crm_lead_formatted_phone.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +import re +from osv import fields, osv + +class crm_lead_formatted_phone(osv.osv): + _inherit = 'crm.lead' + + def on_change_phone(self, cr, uid, ids, field_name, phone, country_id=False): + result = phone + if phone: + digits = [c for c in phone if c.isdigit()] + if len(digits) >= 10: + result = u"(%s) %s-%s" % ("".join(digits[0:3]), "".join(digits[3:6]), + "".join(digits[6:10])) + if len(digits) > 10: + result += " x %s" % "".join(digits[10:]) + return { 'value': { field_name: result } } + +crm_lead_formatted_phone() diff --git a/crm_lead_formatted_phone/crm_lead_formatted_phone.xml b/crm_lead_formatted_phone/crm_lead_formatted_phone.xml new file mode 100644 index 000000000..64daade44 --- /dev/null +++ b/crm_lead_formatted_phone/crm_lead_formatted_phone.xml @@ -0,0 +1,33 @@ + + + + + + crm.lead.formatted.phone.form + crm.lead + + form + + + + + + + + + + + + + + + + + + + + + diff --git a/res_partner_address_formatted_phone/__init__.py b/res_partner_address_formatted_phone/__init__.py new file mode 100644 index 000000000..baebd9a72 --- /dev/null +++ b/res_partner_address_formatted_phone/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +import res_partner_address_formatted_phone +import res_country_phone_format diff --git a/res_partner_address_formatted_phone/__openerp__.py b/res_partner_address_formatted_phone/__openerp__.py new file mode 100644 index 000000000..74d8fb969 --- /dev/null +++ b/res_partner_address_formatted_phone/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +{ + "name" : "Format phone numbers of partner", + "version" : "0.1", + "author" : "Savoir-faire Linux", + "website" : "http://www.savoirfairelinux.com", + "license" : "AGPL-3", + "category" : "Partner", + "description" : """ +This module formats the partner phone numbers based on the format of the +phonenumbers library (http://pypi.python.org/pypi/phonenumbers). + """, + "images" : [], + "depends" : ["base"], + "demo" : [], + "test" : [], + "data" : [ + "res_partner_address_formatted_phone.xml", + "res_country_phone_format_view.xml", + "res_country_phone_format_data.xml", + ], + "installable": True, + "complexity": "easy", +} diff --git a/res_partner_address_formatted_phone/res_country_phone_format.py b/res_partner_address_formatted_phone/res_country_phone_format.py new file mode 100644 index 000000000..79c86d9e2 --- /dev/null +++ b/res_partner_address_formatted_phone/res_country_phone_format.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +import re +from osv import fields, osv + +class res_country_phone_format(osv.osv): + _inherit = 'res.country' + _columns = { + 'phone_format': fields.char('Phone Format', size=100) + } + +res_country_phone_format() diff --git a/res_partner_address_formatted_phone/res_country_phone_format_data.xml b/res_partner_address_formatted_phone/res_country_phone_format_data.xml new file mode 100644 index 000000000..18b3bcea9 --- /dev/null +++ b/res_partner_address_formatted_phone/res_country_phone_format_data.xml @@ -0,0 +1,10 @@ + + + + + + (XXX) XXX-XXXX x XXX + + + + diff --git a/res_partner_address_formatted_phone/res_country_phone_format_view.xml b/res_partner_address_formatted_phone/res_country_phone_format_view.xml new file mode 100644 index 000000000..ed3066c4e --- /dev/null +++ b/res_partner_address_formatted_phone/res_country_phone_format_view.xml @@ -0,0 +1,18 @@ + + + + + + res.country.phone.format.form + res.country + + form + + + + + + + + + diff --git a/res_partner_address_formatted_phone/res_partner_address_formatted_phone.py b/res_partner_address_formatted_phone/res_partner_address_formatted_phone.py new file mode 100644 index 000000000..8b152d896 --- /dev/null +++ b/res_partner_address_formatted_phone/res_partner_address_formatted_phone.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012 Savoir-faire Linux (). +# +# 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 . +# +############################################################################## + +import re +from osv import fields, osv + +class res_partner_address_formatted_phone(osv.osv): + _inherit = 'res.partner.address' + + def on_change_phone(self, cr, uid, ids, field_name, phone, country_id=False): + result = phone + phone_format = self.pool.get('phone_format') + if phone: + digits = [c for c in phone if c.isdigit()] + crosses = [x for x in phone_format if c == 'X'] + if len(digits) >= len(crosses): + result = u"(%s) %s-%s" % ("".join(digits[0:3]), "".join(digits[3:6]), + "".join(digits[6:10])) + if len(digits) > 10: + result += " x %s" % "".join(digits[10:]) + return { 'value': { field_name: result } } + +res_partner_address_formatted_phone() diff --git a/res_partner_address_formatted_phone/res_partner_address_formatted_phone.xml b/res_partner_address_formatted_phone/res_partner_address_formatted_phone.xml new file mode 100644 index 000000000..59dc3806a --- /dev/null +++ b/res_partner_address_formatted_phone/res_partner_address_formatted_phone.xml @@ -0,0 +1,28 @@ + + + + + res.partner.american_phone_formatter.form + res.partner + + form + + + + + + + + + + + + + + + +