Merge lp:~camptocamp/openerp-product-attributes/7.0-add_product_gtin-afe into lp:~product-core-editors/openerp-product-attributes/7.0
- 7.0-add_product_gtin-afe
- Merge into 7.0
Status: | Merged |
---|---|
Merged at revision: | 248 |
Proposed branch: | lp:~camptocamp/openerp-product-attributes/7.0-add_product_gtin-afe |
Merge into: | lp:~product-core-editors/openerp-product-attributes/7.0 |
Diff against target: |
563 lines (+79/-251) 8 files modified
product_gtin/__init__.py (+0/-31) product_gtin/__openerp__.py (+39/-0) product_gtin/__terp__.py (+0/-17) product_gtin/i18n/de.po (+40/-0) product_gtin/i18n/fr_BE.po (+0/-32) product_gtin/i18n/product_gtin.pot (+0/-30) product_gtin/i18n/sv.po (+0/-36) product_gtin/product_gtin.py (+0/-105) |
To merge this branch: | bzr merge lp:~camptocamp/openerp-product-attributes/7.0-add_product_gtin-afe |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guewen Baconnier @ Camptocamp | Approve | ||
Pedro Manuel Baeza | code review | Approve | |
Alexis de Lattre (community) | code review and test | Approve | |
Review via email: mp+222760@code.launchpad.net |
Commit message
Description of the change
replace product_gtin with chricar_
I ported the history of changes of that addon using bazaar-extractor, and Alexis de Lattre did the actual porting to V7 + OCA coding standards
Quentin THEURET @Amaris (qtheuret) wrote : | # |
Alexis de Lattre (alexis-via) wrote : | # |
Alexandre, could you replay my commit revno 249 in the branch lp:~akretion-team/openerp-product-attributes/70-update-and-fix-product-gtin ; it's a small code simplification.
Alexis de Lattre (alexis-via) wrote : | # |
BTW, for those who want to make EAN8 work in the POS, here is the patch for odoo master :
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
LGTM.
Alexis, why don't you propose to odoo to make a method called check_ean_length in the same way as check_ean and use it on PoS, so that we can extend easily PoS codebar recognition via server modules (not JS)?
Regards.
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) : | # |
Preview Diff
1 | === added directory 'product_gtin' |
2 | === removed directory 'product_gtin' |
3 | === added file 'product_gtin/__init__.py' |
4 | --- product_gtin/__init__.py 1970-01-01 00:00:00 +0000 |
5 | +++ product_gtin/__init__.py 2014-06-11 08:42:55 +0000 |
6 | @@ -0,0 +1,26 @@ |
7 | +# -*- coding: utf-8 -*- |
8 | +############################################################################## |
9 | +# |
10 | +# Product GTIN module for OpenERP |
11 | +# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved. |
12 | +# Fabien Pinckaers <fp@tiny.Be> |
13 | +# Copyright (c) 2008 ChriCar Beteilugungs- und Beratungs- GmbH |
14 | +# All Rights Reserved. |
15 | +# Ferdinand Gassauer <tiny@chricar.at> |
16 | +# |
17 | +# This program is free software: you can redistribute it and/or modify |
18 | +# it under the terms of the GNU Affero General Public License as |
19 | +# published by the Free Software Foundation, either version 3 of the |
20 | +# License, or (at your option) any later version. |
21 | +# |
22 | +# This program is distributed in the hope that it will be useful, |
23 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 | +# GNU Affero General Public License for more details. |
26 | +# |
27 | +# You should have received a copy of the GNU Affero General Public License |
28 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
29 | +# |
30 | +############################################################################## |
31 | + |
32 | +from . import product_gtin |
33 | |
34 | === removed file 'product_gtin/__init__.py' |
35 | --- product_gtin/__init__.py 2009-04-09 07:06:02 +0000 |
36 | +++ product_gtin/__init__.py 1970-01-01 00:00:00 +0000 |
37 | @@ -1,31 +0,0 @@ |
38 | -############################################################################## |
39 | -# |
40 | -# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved. |
41 | -# Fabien Pinckaers <fp@tiny.Be> |
42 | -# Copyright (c) 2008 ChriCar Beteilugungs- und Beratungs- GmbH All Rights Reserved. |
43 | -# Ferdinand Gassauer <tiny@chricar.at> |
44 | -# |
45 | -# WARNING: This program as such is intended to be used by professional |
46 | -# programmers who take the whole responsability of assessing all potential |
47 | -# consequences resulting from its eventual inadequacies and bugs |
48 | -# End users who are looking for a ready-to-use solution with commercial |
49 | -# garantees and support are strongly adviced to contract a Free Software |
50 | -# Service Company |
51 | -# |
52 | -# This program is Free Software; you can redistribute it and/or |
53 | -# modify it under the terms of the GNU General Public License |
54 | -# as published by the Free Software Foundation; either version 2 |
55 | -# of the License, or (at your option) any later version. |
56 | -# |
57 | -# This program is distributed in the hope that it will be useful, |
58 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
59 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
60 | -# GNU General Public License for more details. |
61 | -# |
62 | -# You should have received a copy of the GNU General Public License |
63 | -# along with this program; if not, write to the Free Software |
64 | -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
65 | -# |
66 | -############################################################################## |
67 | - |
68 | -import product_gtin |
69 | \ No newline at end of file |
70 | |
71 | === added file 'product_gtin/__openerp__.py' |
72 | --- product_gtin/__openerp__.py 1970-01-01 00:00:00 +0000 |
73 | +++ product_gtin/__openerp__.py 2014-06-11 08:42:55 +0000 |
74 | @@ -0,0 +1,39 @@ |
75 | +# -*- coding: utf-8 -*- |
76 | +############################################################################## |
77 | +# |
78 | +# Product GTIN module for OpenERP |
79 | +# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>). |
80 | +# Copyright (C) 2010-2011 Camptocamp Austria (<http://www.camptocamp.at>) |
81 | +# |
82 | +# This program is free software: you can redistribute it and/or modify |
83 | +# it under the terms of the GNU Affero General Public License as |
84 | +# published by the Free Software Foundation, either version 3 of the |
85 | +# License, or (at your option) any later version. |
86 | +# |
87 | +# This program is distributed in the hope that it will be useful, |
88 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
89 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
90 | +# GNU Affero General Public License for more details. |
91 | +# |
92 | +# You should have received a copy of the GNU Affero General Public License |
93 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
94 | +# |
95 | +############################################################################## |
96 | + |
97 | +{ |
98 | + "name": "Product GTIN EAN8 EAN13 UPC JPC Support", |
99 | + "version": "1.1", |
100 | + "author": "ChriCar Beteiligungs- und Beratungs- GmbH", |
101 | + "website": "http://www.chricar.at/ChriCar", |
102 | + "category": "Sales Management", |
103 | + "depends": ["product"], |
104 | + "description": """ |
105 | +Product GTIN module |
106 | +=================== |
107 | + |
108 | +Replaces the EAN13 field on products, partners and packaging by a field with the same technical name that accepts EAN13, EAN8, JPC, UPC and GTIN. |
109 | + """, |
110 | + "demo": [], |
111 | + "data": [], |
112 | + "installable": True, |
113 | +} |
114 | |
115 | === removed file 'product_gtin/__terp__.py' |
116 | --- product_gtin/__terp__.py 2013-01-21 06:49:06 +0000 |
117 | +++ product_gtin/__terp__.py 1970-01-01 00:00:00 +0000 |
118 | @@ -1,17 +0,0 @@ |
119 | -{ |
120 | - "name" : "Invalid - Please use chricar_product_gtin instead Product GTIN EAN UPC JPC Support", |
121 | - "version" : "1.0", |
122 | - "author" : "ChriCar Beteiligungs- und Beratungs- GmbH", |
123 | - "website" : "http://www.chricar.at/ChriCar", |
124 | - "category" : "Generic Modules/Others", |
125 | - "depends" : ["product"], |
126 | - "description" : """ |
127 | -Replaces the EAN13 code completion with a checkroutine for EAN13, EAN8, UPC and GTIN. |
128 | -It allows to support different types of barcodes systems. |
129 | - """, |
130 | - "init_xml" : [], |
131 | - "demo_xml" : [], |
132 | - "update_xml" : [], |
133 | - "active": False, |
134 | - 'installable': False |
135 | -} |
136 | |
137 | === added directory 'product_gtin/i18n' |
138 | === removed directory 'product_gtin/i18n' |
139 | === added file 'product_gtin/i18n/de.po' |
140 | --- product_gtin/i18n/de.po 1970-01-01 00:00:00 +0000 |
141 | +++ product_gtin/i18n/de.po 2014-06-11 08:42:55 +0000 |
142 | @@ -0,0 +1,40 @@ |
143 | +# Translation of OpenERP Server. |
144 | +# This file contains the translation of the following modules: |
145 | +# * chricar_product_gtin |
146 | +# |
147 | +msgid "" |
148 | +msgstr "" |
149 | +"Project-Id-Version: OpenERP Server 6.1rc1\n" |
150 | +"Report-Msgid-Bugs-To: \n" |
151 | +"POT-Creation-Date: 2012-01-23 22:06+0000\n" |
152 | +"PO-Revision-Date: 2012-01-24 01:28+0000\n" |
153 | +"Last-Translator: Joël Grand-Guillaume @ CampToCamp " |
154 | +"<joel.grandguillaume@camptocamp.com>\n" |
155 | +"Language-Team: \n" |
156 | +"MIME-Version: 1.0\n" |
157 | +"Content-Type: text/plain; charset=UTF-8\n" |
158 | +"Content-Transfer-Encoding: 8bit\n" |
159 | +"X-Launchpad-Export-Date: 2012-10-23 05:13+0000\n" |
160 | +"X-Generator: Launchpad (build 16179)\n" |
161 | + |
162 | +#. module: chricar_product_gtin |
163 | +#: model:ir.model,name:chricar_product_gtin.model_product_packaging |
164 | +msgid "Packaging" |
165 | +msgstr "Verpackung" |
166 | + |
167 | +#. module: chricar_product_gtin |
168 | +#: model:ir.model,name:chricar_product_gtin.model_res_partner |
169 | +msgid "Partner" |
170 | +msgstr "Partner" |
171 | + |
172 | +#. module: chricar_product_gtin |
173 | +#: model:ir.model,name:chricar_product_gtin.model_product_product |
174 | +msgid "Product" |
175 | +msgstr "Produkt" |
176 | + |
177 | +#. module: chricar_product_gtin |
178 | +#: constraint:product.packaging:0 |
179 | +#: constraint:product.product:0 |
180 | +#: constraint:res.partner:0 |
181 | +msgid "Error: Invalid EAN code" |
182 | +msgstr "Fehler: ungültiger EAN Code" |
183 | |
184 | === removed file 'product_gtin/i18n/fr_BE.po' |
185 | --- product_gtin/i18n/fr_BE.po 2014-05-17 07:09:00 +0000 |
186 | +++ product_gtin/i18n/fr_BE.po 1970-01-01 00:00:00 +0000 |
187 | @@ -1,32 +0,0 @@ |
188 | -# Translation of OpenERP Server. |
189 | -# This file contains the translation of the following modules: |
190 | -# * product_gtin |
191 | -# |
192 | -msgid "" |
193 | -msgstr "" |
194 | -"Project-Id-Version: OpenERP Server 5.0.6\n" |
195 | -"Report-Msgid-Bugs-To: support@openerp.com\n" |
196 | -"POT-Creation-Date: 2009-11-25 13:29+0000\n" |
197 | -"PO-Revision-Date: 2014-03-11 12:21+0000\n" |
198 | -"Last-Translator: <>\n" |
199 | -"Language-Team: \n" |
200 | -"MIME-Version: 1.0\n" |
201 | -"Content-Type: text/plain; charset=UTF-8\n" |
202 | -"Content-Transfer-Encoding: 8bit\n" |
203 | -"X-Launchpad-Export-Date: 2014-05-17 07:08+0000\n" |
204 | -"X-Generator: Launchpad (build 17007)\n" |
205 | - |
206 | -#. module: product_gtin |
207 | -#: model:ir.module.module,description:product_gtin.module_meta_information |
208 | -msgid "" |
209 | -"\n" |
210 | -"Replaces the EAN13 code completion with a checkroutine for EAN13, EAN8, UPC " |
211 | -"and GTIN.\n" |
212 | -"It allows to support different types of barcodes systems.\n" |
213 | -" " |
214 | -msgstr "" |
215 | - |
216 | -#. module: product_gtin |
217 | -#: model:ir.module.module,shortdesc:product_gtin.module_meta_information |
218 | -msgid "Product GTIN EAN UPC JPC Support" |
219 | -msgstr "" |
220 | |
221 | === added file 'product_gtin/i18n/product_gtin.pot' |
222 | --- product_gtin/i18n/product_gtin.pot 1970-01-01 00:00:00 +0000 |
223 | +++ product_gtin/i18n/product_gtin.pot 2014-06-11 08:42:55 +0000 |
224 | @@ -0,0 +1,39 @@ |
225 | +# Translation of OpenERP Server. |
226 | +# This file contains the translation of the following modules: |
227 | +# * product_gtin |
228 | +# |
229 | +msgid "" |
230 | +msgstr "" |
231 | +"Project-Id-Version: OpenERP Server 7.0\n" |
232 | +"Report-Msgid-Bugs-To: \n" |
233 | +"POT-Creation-Date: 2014-06-10 22:04+0000\n" |
234 | +"PO-Revision-Date: 2014-06-10 22:04+0000\n" |
235 | +"Last-Translator: <>\n" |
236 | +"Language-Team: \n" |
237 | +"MIME-Version: 1.0\n" |
238 | +"Content-Type: text/plain; charset=UTF-8\n" |
239 | +"Content-Transfer-Encoding: \n" |
240 | +"Plural-Forms: \n" |
241 | + |
242 | +#. module: product_gtin |
243 | +#: constraint:product.packaging:0 |
244 | +#: constraint:product.product:0 |
245 | +#: constraint:res.partner:0 |
246 | +msgid "Error: Invalid EAN code" |
247 | +msgstr "" |
248 | + |
249 | +#. module: product_gtin |
250 | +#: model:ir.model,name:product_gtin.model_product_packaging |
251 | +msgid "Packaging" |
252 | +msgstr "" |
253 | + |
254 | +#. module: product_gtin |
255 | +#: model:ir.model,name:product_gtin.model_res_partner |
256 | +msgid "Partner" |
257 | +msgstr "" |
258 | + |
259 | +#. module: product_gtin |
260 | +#: model:ir.model,name:product_gtin.model_product_product |
261 | +msgid "Product" |
262 | +msgstr "" |
263 | + |
264 | |
265 | === removed file 'product_gtin/i18n/product_gtin.pot' |
266 | --- product_gtin/i18n/product_gtin.pot 2010-01-04 05:32:54 +0000 |
267 | +++ product_gtin/i18n/product_gtin.pot 1970-01-01 00:00:00 +0000 |
268 | @@ -1,30 +0,0 @@ |
269 | -# Translation of OpenERP Server. |
270 | -# This file contains the translation of the following modules: |
271 | -# * product_gtin |
272 | -# |
273 | -msgid "" |
274 | -msgstr "" |
275 | -"Project-Id-Version: OpenERP Server 5.0.6\n" |
276 | -"Report-Msgid-Bugs-To: support@openerp.com\n" |
277 | -"POT-Creation-Date: 2009-11-25 13:29:40+0000\n" |
278 | -"PO-Revision-Date: 2009-11-25 13:29:40+0000\n" |
279 | -"Last-Translator: <>\n" |
280 | -"Language-Team: \n" |
281 | -"MIME-Version: 1.0\n" |
282 | -"Content-Type: text/plain; charset=UTF-8\n" |
283 | -"Content-Transfer-Encoding: \n" |
284 | -"Plural-Forms: \n" |
285 | - |
286 | -#. module: product_gtin |
287 | -#: model:ir.module.module,description:product_gtin.module_meta_information |
288 | -msgid "\n" |
289 | -"Replaces the EAN13 code completion with a checkroutine for EAN13, EAN8, UPC and GTIN.\n" |
290 | -"It allows to support different types of barcodes systems.\n" |
291 | -" " |
292 | -msgstr "" |
293 | - |
294 | -#. module: product_gtin |
295 | -#: model:ir.module.module,shortdesc:product_gtin.module_meta_information |
296 | -msgid "Product GTIN EAN UPC JPC Support" |
297 | -msgstr "" |
298 | - |
299 | |
300 | === removed file 'product_gtin/i18n/sv.po' |
301 | --- product_gtin/i18n/sv.po 2014-05-17 07:09:00 +0000 |
302 | +++ product_gtin/i18n/sv.po 1970-01-01 00:00:00 +0000 |
303 | @@ -1,36 +0,0 @@ |
304 | -# Translation of OpenERP Server. |
305 | -# This file contains the translation of the following modules: |
306 | -# * product_gtin |
307 | -# |
308 | -msgid "" |
309 | -msgstr "" |
310 | -"Project-Id-Version: OpenERP Server 5.0.14\n" |
311 | -"Report-Msgid-Bugs-To: support@openerp.com\n" |
312 | -"POT-Creation-Date: 2009-11-25 13:29+0000\n" |
313 | -"PO-Revision-Date: 2014-03-11 12:44+0000\n" |
314 | -"Last-Translator: Graeme Gellatly <Unknown>\n" |
315 | -"Language-Team: \n" |
316 | -"MIME-Version: 1.0\n" |
317 | -"Content-Type: text/plain; charset=UTF-8\n" |
318 | -"Content-Transfer-Encoding: 8bit\n" |
319 | -"X-Launchpad-Export-Date: 2014-05-17 07:08+0000\n" |
320 | -"X-Generator: Launchpad (build 17007)\n" |
321 | - |
322 | -#. module: product_gtin |
323 | -#: model:ir.module.module,description:product_gtin.module_meta_information |
324 | -msgid "" |
325 | -"\n" |
326 | -"Replaces the EAN13 code completion with a checkroutine for EAN13, EAN8, UPC " |
327 | -"and GTIN.\n" |
328 | -"It allows to support different types of barcodes systems.\n" |
329 | -" " |
330 | -msgstr "" |
331 | -"\n" |
332 | -"Ersätter EAN13-koden med en kontrollrutin för EAN13, EAN8, UPC och GTIN.\n" |
333 | -"den tillåter användning av flera typer av streckkodsystem.\n" |
334 | -" " |
335 | - |
336 | -#. module: product_gtin |
337 | -#: model:ir.module.module,shortdesc:product_gtin.module_meta_information |
338 | -msgid "Product GTIN EAN UPC JPC Support" |
339 | -msgstr "Product GTIN EAN UPC JPC Support" |
340 | |
341 | === added file 'product_gtin/product_gtin.py' |
342 | --- product_gtin/product_gtin.py 1970-01-01 00:00:00 +0000 |
343 | +++ product_gtin/product_gtin.py 2014-06-11 08:42:55 +0000 |
344 | @@ -0,0 +1,109 @@ |
345 | +# -*- coding: utf-8 -*- |
346 | +############################################################################## |
347 | +# |
348 | +# Product GTIN module for OpenERP |
349 | +# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>). |
350 | +# Copyright (C) 2010-2011 Camptocamp (<http://www.camptocamp.at>) |
351 | +# |
352 | +# This program is free software: you can redistribute it and/or modify |
353 | +# it under the terms of the GNU Affero General Public License as |
354 | +# published by the Free Software Foundation, either version 3 of the |
355 | +# License, or (at your option) any later version. |
356 | +# |
357 | +# This program is distributed in the hope that it will be useful, |
358 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
359 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
360 | +# GNU Affero General Public License for more details. |
361 | +# |
362 | +# You should have received a copy of the GNU Affero General Public License |
363 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
364 | +# |
365 | +############################################################################## |
366 | + |
367 | +from openerp.osv import orm, fields |
368 | +import operator |
369 | + |
370 | + |
371 | +def is_pair(x): |
372 | + return not x % 2 |
373 | + |
374 | + |
375 | +def check_ean(eancode): |
376 | + if not eancode: |
377 | + return True |
378 | + if not len(eancode) in [8, 12, 13, 14]: |
379 | + return False |
380 | + try: |
381 | + int(eancode) |
382 | + except: |
383 | + return False |
384 | + sum = 0 |
385 | + ean13_len = int(len(eancode)) |
386 | + for i in range(ean13_len-1): |
387 | + pos = int(ean13_len-2-i) |
388 | + if is_pair(i): |
389 | + sum += 3 * int(eancode[pos]) |
390 | + else: |
391 | + sum += int(eancode[pos]) |
392 | + check = 10 - operator.mod(sum, 10) |
393 | + if check == 10: |
394 | + check = 0 |
395 | + if check != int(eancode[ean13_len-1]): # last digit |
396 | + return False |
397 | + return True |
398 | + |
399 | + |
400 | +class product_product(orm.Model): |
401 | + _inherit = "product.product" |
402 | + |
403 | + def _check_ean_key(self, cr, uid, ids): |
404 | + for rec in self.browse(cr, uid, ids): |
405 | + if not check_ean(rec.ean13): |
406 | + return False |
407 | + return True |
408 | + |
409 | + _columns = { |
410 | + 'ean13': fields.char( |
411 | + 'EAN', size=14, |
412 | + help="Code for EAN8 EAN13 UPC JPC GTIN " |
413 | + "http://en.wikipedia.org/wiki/Global_Trade_Item_Number"), |
414 | + } |
415 | + |
416 | + _constraints = [(_check_ean_key, 'Error: Invalid EAN code', ['ean13'])] |
417 | + |
418 | + |
419 | +class product_packaging(orm.Model): |
420 | + _inherit = "product.packaging" |
421 | + |
422 | + def _check_ean_key(self, cr, uid, ids): |
423 | + for rec in self.browse(cr, uid, ids): |
424 | + if not check_ean(rec.ean): |
425 | + return False |
426 | + return True |
427 | + |
428 | + _columns = { |
429 | + 'ean': fields.char( |
430 | + 'EAN', size=14, |
431 | + help='Barcode number for EAN8 EAN13 UPC JPC GTIN'), |
432 | + } |
433 | + |
434 | + _constraints = [(_check_ean_key, 'Error: Invalid EAN code', ['ean'])] |
435 | + |
436 | + |
437 | +class res_partner(orm.Model): |
438 | + _inherit = "res.partner" |
439 | + |
440 | + def _check_ean_key(self, cr, uid, ids): |
441 | + for rec in self.browse(cr, uid, ids): |
442 | + if not check_ean(rec.ean13): |
443 | + return False |
444 | + return True |
445 | + |
446 | + _columns = { |
447 | + 'ean13': fields.char( |
448 | + 'EAN', size=14, |
449 | + help="Code for EAN8 EAN13 UPC JPC GTIN " |
450 | + "http://en.wikipedia.org/wiki/Global_Trade_Item_Number"), |
451 | + } |
452 | + |
453 | + _constraints = [(_check_ean_key, 'Error: Invalid EAN code', ['ean13'])] |
454 | |
455 | === removed file 'product_gtin/product_gtin.py' |
456 | --- product_gtin/product_gtin.py 2009-04-09 07:06:02 +0000 |
457 | +++ product_gtin/product_gtin.py 1970-01-01 00:00:00 +0000 |
458 | @@ -1,105 +0,0 @@ |
459 | -# -*- encoding: utf-8 -*- |
460 | -############################################################################## |
461 | -# |
462 | -# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. |
463 | -# |
464 | -# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $ |
465 | -# |
466 | -# WARNING: This program as such is intended to be used by professional |
467 | -# programmers who take the whole responsability of assessing all potential |
468 | -# consequences resulting from its eventual inadequacies and bugs |
469 | -# End users who are looking for a ready-to-use solution with commercial |
470 | -# garantees and support are strongly adviced to contract a Free Software |
471 | -# Service Company |
472 | -# |
473 | -# This program is Free Software; you can redistribute it and/or |
474 | -# modify it under the terms of the GNU General Public License |
475 | -# as published by the Free Software Foundation; either version 2 |
476 | -# of the License, or (at your option) any later version. |
477 | -# |
478 | -# This program is distributed in the hope that it will be useful, |
479 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
480 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
481 | -# GNU General Public License for more details. |
482 | -# |
483 | -# You should have received a copy of the GNU General Public License |
484 | -# along with this program; if not, write to the Free Software |
485 | -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
486 | -# |
487 | -############################################################################## |
488 | - |
489 | - |
490 | -import netsvc |
491 | -from osv import fields, osv |
492 | -#import pooler |
493 | -#import wizard |
494 | -import math |
495 | -#from _common import rounding |
496 | - |
497 | -#import product |
498 | - |
499 | -# need to replace the check_ean_key function |
500 | -class product_product(osv.osv): |
501 | - _inherit = "product.product" |
502 | - _name = "product.product" |
503 | - _columns = { |
504 | - 'ean13': fields.char('EAN UPC JPC GTIN', size=14), |
505 | - } |
506 | - def _check_ean_key(self, cr, uid, ids): |
507 | - def is_pair(x): |
508 | - return not x%2 |
509 | - for product in self.browse(cr, uid, ids): |
510 | - if not product.ean13: |
511 | - continue |
512 | - if not len(product.ean13) in [8,12,13,14]: |
513 | - return False |
514 | - try: |
515 | - int(product.ean13) |
516 | - except: |
517 | - return False |
518 | - sum=0 |
519 | - ean_len=len(product.ean13) |
520 | - for i in range(ean_len-1): |
521 | - pos=int(ean_len-2-i) |
522 | - if is_pair(i): |
523 | - sum += 3 * int(product.ean13[pos]) |
524 | - else: |
525 | - sum += int(product.ean13[pos]) |
526 | - check = int(math.ceil(sum / 10.0) * 10 - sum) |
527 | - if check != int(product.ean13[ean_len-1]): # last digit |
528 | - return False |
529 | - return True |
530 | - _constraints = [(_check_ean_key, 'Error: Invalid EAN,UPC,JPC,GTIN code', ['ean13'])] |
531 | -product_product() |
532 | - |
533 | -class res_partner(osv.osv): |
534 | - _inherit = "res.partner" |
535 | - def _check_ean_key(self, cr, uid, ids): |
536 | - def is_pair(x): |
537 | - return not x%2 |
538 | - for partner in self.browse(cr, uid, ids): |
539 | - if not partner.ean13: |
540 | - continue |
541 | - if not len(partner.ean13) in [8,12,13,14]: |
542 | - return False |
543 | - try: |
544 | - int(partner.ean13) |
545 | - except: |
546 | - return False |
547 | - sum=0 |
548 | - ean_len=len(partner.ean13) |
549 | - for i in range(ean_len-1): |
550 | - pos=int(ean_len-2-i) |
551 | - if is_pair(i): |
552 | - sum += 3 * int(partner.ean13[pos]) |
553 | - else: |
554 | - sum += int(partner.ean13[pos]) |
555 | - check = int(math.ceil(sum / 10.0) * 10 - sum) |
556 | - if check != int(partner.ean13[ean_len-1]): # last digit |
557 | - return False |
558 | - return True |
559 | - |
560 | - _constraints = [(_check_ean_key, 'Error: Invalid EAN,UPC,JPC,GTIN code', ['ean13'])] |
561 | - |
562 | -res_partner() |
563 | - |
LGTM