Browse Source
[ADD] res_partner_address_formatted_phone
[ADD] res_partner_address_formatted_phone
[ADD] crm_lead_formatted_phone Needs rewriting to get regex from res.country and maybe use phonenumbers lib
Maxime Chambreuil
12 years ago
11 changed files with 330 additions and 0 deletions
-
22crm_lead_formatted_phone/__init__.py
-
41crm_lead_formatted_phone/__openerp__.py
-
39crm_lead_formatted_phone/crm_lead_formatted_phone.py
-
33crm_lead_formatted_phone/crm_lead_formatted_phone.xml
-
23res_partner_address_formatted_phone/__init__.py
-
44res_partner_address_formatted_phone/__openerp__.py
-
31res_partner_address_formatted_phone/res_country_phone_format.py
-
10res_partner_address_formatted_phone/res_country_phone_format_data.xml
-
18res_partner_address_formatted_phone/res_country_phone_format_view.xml
-
41res_partner_address_formatted_phone/res_partner_address_formatted_phone.py
-
28res_partner_address_formatted_phone/res_partner_address_formatted_phone.xml
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
import crm_lead_formatted_phone |
@ -0,0 +1,41 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
"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", |
|||
} |
@ -0,0 +1,39 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
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() |
@ -0,0 +1,33 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="crm_lead_formatted_phone_form"> |
|||
<field name="name">crm.lead.formatted.phone.form</field> |
|||
<field name="model">crm.lead</field> |
|||
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/> |
|||
<field name="type">form</field> |
|||
<field name="arch" type="xml"> |
|||
<data> |
|||
|
|||
<xpath expr="//notebook/page[@string='Lead']/group/field[@name='phone']" |
|||
position="replace"> |
|||
<field name="phone" on_change="on_change_phone('phone', phone, country_id)"/> |
|||
</xpath> |
|||
|
|||
<xpath expr="//notebook/page[@string='Lead']/group/field[@name='mobile']" |
|||
position="replace"> |
|||
<field name="mobile" on_change="on_change_phone('mobile', mobile, country_id)"/> |
|||
</xpath> |
|||
|
|||
<xpath expr="//notebook/page[@string='Lead']/group/field[@name='fax']" |
|||
position="replace"> |
|||
<field name="fax" on_change="on_change_phone('fax', fax, country_id)"/> |
|||
</xpath> |
|||
|
|||
</data> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
import res_partner_address_formatted_phone |
|||
import res_country_phone_format |
@ -0,0 +1,44 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
"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", |
|||
} |
@ -0,0 +1,31 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
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() |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data noupdate="1"> |
|||
|
|||
<record model="res.country" id="base.ca"> |
|||
<field name="phone_format">(XXX) XXX-XXXX x XXX</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="view_res_country_phone_format_form"> |
|||
<field name="name">res.country.phone.format.form</field> |
|||
<field name="model">res.country</field> |
|||
<field name="inherit_id" ref="base.view_country_form"/> |
|||
<field name="type">form</field> |
|||
<field name="arch" type="xml"> |
|||
<field name="address_format" position="after"> |
|||
<field name="phone_format"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,41 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>). |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
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() |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
<record model="ir.ui.view" |
|||
id="view_customer_american_phone_formatter_form"> |
|||
<field name="name">res.partner.american_phone_formatter.form</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form" /> |
|||
<field name="type">form</field> |
|||
<field name="arch" type="xml"> |
|||
<data> |
|||
<xpath expr="//notebook/page[@string='General']/field/form//group/field[@name='phone']" |
|||
position="replace"> |
|||
<field name="phone" on_change="on_change_phone('phone', phone, country_id)" /> |
|||
</xpath> |
|||
<xpath expr="//notebook/page[@string='General']/field/form//group/field[@name='mobile']" |
|||
position="replace"> |
|||
<field name="mobile" on_change="on_change_phone('mobile', mobile, country_id)" /> |
|||
</xpath> |
|||
<xpath expr="//notebook/page[@string='General']/field/form//group/field[@name='fax']" |
|||
position="replace"> |
|||
<field name="fax" on_change="on_change_phone('fax', fax, country_id)" /> |
|||
</xpath> |
|||
</data> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue