From af5cc18fb4ab0e58d546959255ea91d0328914c4 Mon Sep 17 00:00:00 2001 From: "david.beal@akretion.com" Date: Mon, 8 Sep 2014 17:06:13 +0200 Subject: [PATCH 1/5] [ADD] module base_partner_helper --- base_partner_helper/__init__.py | 22 ++++++++++ base_partner_helper/__openerp__.py | 64 ++++++++++++++++++++++++++++ base_partner_helper/partner.py | 67 ++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 base_partner_helper/__init__.py create mode 100644 base_partner_helper/__openerp__.py create mode 100644 base_partner_helper/partner.py diff --git a/base_partner_helper/__init__.py b/base_partner_helper/__init__.py new file mode 100644 index 000000000..590716ea0 --- /dev/null +++ b/base_partner_helper/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Sébastien BEAU +# Copyright 2014 Akretion +# +# 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 partner # noqa diff --git a/base_partner_helper/__openerp__.py b/base_partner_helper/__openerp__.py new file mode 100644 index 000000000..ab42f5bcc --- /dev/null +++ b/base_partner_helper/__openerp__.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Sébastien BEAU +# Copyright 2014 Akretion +# +# 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': 'Partner Helper', + 'version': '0.1', + 'author': 'Akretion', + 'maintainer': 'Akretion', + 'category': 'Warehouse', + 'depends': [ + 'base', + ], + 'description': """ +Partner Helper +============== +The purpose of this module is to gather generic partner methods in the same module. +It avoid to grow up excessively the number of module in Odoo for small features. + +Description +----------- +Add specific helper methods to deal with partners: + +* _get_split_address(): + This method allows to get a number of street fields according to + your choice. 2 fields by default in Odoo with 128 width chars. + In some countries you have constraints on width of street fields and you + should use 3 or 4 shorter fields. + You also need of this feature to avoid headache with overflow printing task + +* other_method(): + +Contributors +------------ +* Sébastien BEAU +* David BEAL + + + """, + 'website': 'http://www.akretion.com/', + 'data': [], + 'tests': [], + 'installable': True, + 'auto_install': False, + 'license': 'AGPL-3', + 'application': False, +} diff --git a/base_partner_helper/partner.py b/base_partner_helper/partner.py new file mode 100644 index 000000000..82e644970 --- /dev/null +++ b/base_partner_helper/partner.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Sébastien BEAU +# Copyright 2014 Akretion +# +# 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.osv import orm + + +def split_char(char, output_number, size): + words = char.split(' ') + result = [] + word = words.pop(0) + for index in range(0, output_number): + result.append(word) + word = '' + while len(words) > 0: + word = words.pop(0) + if len(result[index] + ' %s' % word) > size: + break + else: + result[index] += ' %s' % word + word = '' + return result + + +class ResPartner(orm.Model): + _inherit = "res.partner" + + def _get_split_address( + self, cr, uid, partner, output_number, max_size, context=None): + """ This method allows to get a number of street fields according to + your choice. Default is 2 large fields in Odoo (128 chars). + In some countries you may use 3 or 4 shorter street fields. + + example: + res = self.pool['res.partner']._get_split_address( + cr, uid, picking.partner_id, 3, 35, context=context) + address['street'], address['street2'], address['street3'] = res + """ + street = partner.street or '' + street2 = partner.street2 or '' + if len(street) <= max_size and len(street2) <= max_size: + result = ['' for i in range(0, output_number)] + result[0] = street + result[1] = street2 + return result + elif street <= max_size: + return [street] + split_char(street2, output_number - 1, max_size) + else: + return split_char('%s %s' % (street, street2), output_number, max_size) + From 680b80b75d21eac70b2915384623f580ace78d02 Mon Sep 17 00:00:00 2001 From: "david.beal@akretion.com" Date: Tue, 9 Sep 2014 09:45:58 +0200 Subject: [PATCH 2/5] [FIX] PEP8 --- base_partner_helper/__openerp__.py | 4 ++-- base_partner_helper/partner.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/base_partner_helper/__openerp__.py b/base_partner_helper/__openerp__.py index ab42f5bcc..174f17fe8 100644 --- a/base_partner_helper/__openerp__.py +++ b/base_partner_helper/__openerp__.py @@ -31,8 +31,8 @@ 'description': """ Partner Helper ============== -The purpose of this module is to gather generic partner methods in the same module. -It avoid to grow up excessively the number of module in Odoo for small features. +The purpose of this module is to gather generic partner methods. +It avoid to grow up excessively the number of module in Odoo for small features Description ----------- diff --git a/base_partner_helper/partner.py b/base_partner_helper/partner.py index 82e644970..569bf5dc7 100644 --- a/base_partner_helper/partner.py +++ b/base_partner_helper/partner.py @@ -63,5 +63,5 @@ class ResPartner(orm.Model): elif street <= max_size: return [street] + split_char(street2, output_number - 1, max_size) else: - return split_char('%s %s' % (street, street2), output_number, max_size) - + return split_char( + '%s %s' % (street, street2), output_number, max_size) From e0ea919002446adbf8a3980602410447caf54577 Mon Sep 17 00:00:00 2001 From: "david.beal@akretion.com" Date: Tue, 9 Sep 2014 10:01:48 +0200 Subject: [PATCH 3/5] [FIX] writing description --- base_partner_helper/__openerp__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_partner_helper/__openerp__.py b/base_partner_helper/__openerp__.py index 174f17fe8..adc760d1d 100644 --- a/base_partner_helper/__openerp__.py +++ b/base_partner_helper/__openerp__.py @@ -32,7 +32,8 @@ Partner Helper ============== The purpose of this module is to gather generic partner methods. -It avoid to grow up excessively the number of module in Odoo for small features +It avoids to grow up excessively the number of module in Odoo +for small features Description ----------- From 8309a68cd336bb5923dca23622129eed01e3ef19 Mon Sep 17 00:00:00 2001 From: "david.beal@akretion.com" Date: Tue, 9 Sep 2014 10:13:46 +0200 Subject: [PATCH 4/5] [FIX] writing again, i shouldn't commit the morning --- base_partner_helper/__openerp__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base_partner_helper/__openerp__.py b/base_partner_helper/__openerp__.py index adc760d1d..6692659d8 100644 --- a/base_partner_helper/__openerp__.py +++ b/base_partner_helper/__openerp__.py @@ -32,8 +32,8 @@ Partner Helper ============== The purpose of this module is to gather generic partner methods. -It avoids to grow up excessively the number of module in Odoo -for small features +It avoids to grow up excessively the number of modules in Odoo +for small features. Description ----------- From ae2b25ce4ea396ea3199e28a121908e8d6a75760 Mon Sep 17 00:00:00 2001 From: "david.beal@akretion.com" Date: Sat, 13 Sep 2014 17:10:28 +0200 Subject: [PATCH 5/5] [IMP] rename module to partner_helper according to pedro request --- {base_partner_helper => partner_helper}/__init__.py | 0 {base_partner_helper => partner_helper}/__openerp__.py | 0 {base_partner_helper => partner_helper}/partner.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {base_partner_helper => partner_helper}/__init__.py (100%) rename {base_partner_helper => partner_helper}/__openerp__.py (100%) rename {base_partner_helper => partner_helper}/partner.py (100%) diff --git a/base_partner_helper/__init__.py b/partner_helper/__init__.py similarity index 100% rename from base_partner_helper/__init__.py rename to partner_helper/__init__.py diff --git a/base_partner_helper/__openerp__.py b/partner_helper/__openerp__.py similarity index 100% rename from base_partner_helper/__openerp__.py rename to partner_helper/__openerp__.py diff --git a/base_partner_helper/partner.py b/partner_helper/partner.py similarity index 100% rename from base_partner_helper/partner.py rename to partner_helper/partner.py