1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
31
from tools.misc import UpdateableStr
37
def _get_ean_key(string):
38
if not string or string=='':
48
return str(int(math.ceil(sum/10.0)*10-sum))
50
#FIXME: this is not concurrency safe !!!!
51
_check_arch = UpdateableStr()
54
def _check_key(self, cr, uid, data, context):
55
partner_table=pooler.get_pool(cr.dbname).get('res.partner')
56
partners = partner_table.browse(cr, uid, data['ids'])
57
_check_arch_lst=['<?xml version="1.0"?>', '<form string="Check EAN13">', '<label string=""/>', '<label string=""/>','<label string="Original" />', '<label string="Computed" />']
58
for partner in partners:
59
if partner['ean13'] and len(partner['ean13'])>11 and len(partner['ean13'])<14:
60
_check_arch_lst.append('<label colspan="2" string="%s" />' % partner['ean13']);
61
key=_get_ean_key(partner['ean13'][:12])
62
_check_arch_lst.append('<label string=""/>')
63
if len(partner['ean13'])==12:
64
_check_arch_lst.append('<label string="" />');
66
_check_arch_lst.append('<label string="%s" />' % partner['ean13'][12])
67
_check_arch_lst.append('<label string="%s" />' % key)
68
_check_arch_lst.append('</form>')
69
_check_arch.string = '\n'.join(_check_arch_lst)
72
def _update_ean(self, cr, uid, data, context):
73
partner_table = pooler.get_pool(cr.dbname).get('res.partner')
74
partners = partner_table.browse(cr, uid, data['ids'])
75
for partner in partners:
76
partner_table.write(cr, uid, data['ids'], {
77
'ean13': "%s%s" % (partner['ean13'][:12], _get_ean_key(partner['ean13'][:12]))
81
class wiz_ean_check(wizard.interface):
84
'actions': [_check_key],
88
'fields': _check_fields,
89
'state': (('end', 'Ignore'), ('correct', 'Correct EAN13'))
93
'actions': [_update_ean],
101
wiz_ean_check('res.partner.ean13')