1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2006 ACYSOS S.L. (http://acysos.com) All Rights Reserved.
6
# Pedro Tarrafeta <pedro@acysos.com>
7
# Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
8
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
9
# Jordi Esteve <jesteve@zikzakmedia.com>
10
# Copyright (c) 2009 NaN (http://www.nan-tic.com) All Rights Reserved.
11
# Albert Cervera i Areny <albert@nan-tic.com>
14
# This program is free software: you can redistribute it and/or modify
15
# it under the terms of the GNU General Public License as published by
16
# the Free Software Foundation, either version 3 of the License, or
17
# (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
##############################################################################
29
from tools.translate import _
31
def digits_only(cc_in):
32
"""Discards non-numeric chars"""
44
"""Converts special characters such as those with accents to their ASCII equivalents"""
45
old_chars = ['á','é','í','ó','ú','à','è','ì','ò','ù','ä','ë','ï','ö','ü','â','ê','î','ô','û','Á','É','Í','Ú','Ó','À','È','Ì','Ò','Ù','Ä','Ë','Ï','Ö','Ü','Â','Ê','Î','Ô','Û','ñ','Ñ','ç','Ç','ª','º']
46
new_chars = ['a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','A','E','I','O','U','A','E','I','O','U','A','E','I','O','U','A','E','I','O','U','n','N','c','C','a','o']
47
for old, new in zip(old_chars, new_chars):
48
text = text.replace(unicode(old,'UTF-8'), new)
53
def __init__(self, content = '', error = False):
54
self.content = content
56
def add(self, s, error=True):
57
self.content = self.content + s
65
def convert_text(text, size):
66
return to_ascii(text)[:size].ljust(size)
68
def convert_float(cr, number, size, context):
69
text = str( int( round( number * 100, 0 ) ) )
71
raise Log(_('Error:\n\nCan not convert float number %(number).2f to fit in %(size)d characters.') % {
75
return text.zfill(size)
77
def convert_int(cr, number, size, context):
80
raise Log( _('Error:\n\nCan not convert integer number %(number)d to fit in %(size)d characters.') % {
84
return text.zfill(size)
86
def convert(cr, value, size, context):
88
return convert_text('', size)
89
elif isinstance(value, float):
90
return convert_float(cr, value, size, context)
91
elif isinstance(value, int):
92
return convert_int(cr, value, size, context)
94
return convert_text(value, size)
96
def convert_bank_account(cr, value, partner_name, context):
97
if not isinstance(value, basestring):
98
raise Log( _('User error:\n\nThe bank account number of %s is not defined.') % partner_name )
99
ccc = digits_only(value)
101
raise Log( _('User error:\n\nThe bank account number of %s does not have 20 digits.') % partner_name )
104
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: