Browse Source

Merge pull request #29 from bealdav/7.0-partner-helper

[ADD] module partner_helper
pull/32/head
Pedro M. Baeza 10 years ago
parent
commit
0da554485d
  1. 22
      partner_helper/__init__.py
  2. 65
      partner_helper/__openerp__.py
  3. 67
      partner_helper/partner.py

22
partner_helper/__init__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Sébastien BEAU <sebastien.beau@akretion.com>
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import partner # noqa

65
partner_helper/__openerp__.py

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Sébastien BEAU <sebastien.beau@akretion.com>
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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.
It avoids to grow up excessively the number of modules 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 <sebastien.beau@akretion.com>
* David BEAL <david.beal@akretion.com>
""",
'website': 'http://www.akretion.com/',
'data': [],
'tests': [],
'installable': True,
'auto_install': False,
'license': 'AGPL-3',
'application': False,
}

67
partner_helper/partner.py

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Sébastien BEAU <sebastien.beau@akretion.com>
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)
Loading…
Cancel
Save