forked from OCA/partner-contact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
partner.py
67 lines (60 loc) · 2.53 KB
/
partner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Sébastien BEAU <[email protected]>
# 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)