[IMP] point_of_sale: removed duplicated ean check code

bzr revid: fva@openerp.com-20120726095315-2e5c7r0a3gouymcc
This commit is contained in:
Frédéric van der Essen 2012-07-26 11:53:15 +02:00
parent 4201c58f36
commit e4d0897734
2 changed files with 3 additions and 36 deletions

View File

@ -1,38 +1,8 @@
#!/usr/bin/env python
from osv import osv, fields
import math
import openerp.addons.product.product
def is_pair(x):
return not x%2
# This code is a duplicate of product#check_ean function
def check_ean(eancode):
if not eancode:
return True
if len(eancode) <> 13:
return False
try:
int(eancode)
except:
return False
oddsum=0
evensum=0
total=0
eanvalue=eancode
reversevalue = eanvalue[::-1]
finalean=reversevalue[1:]
for i in range(len(finalean)):
if is_pair(i):
oddsum += int(finalean[i])
else:
evensum += int(finalean[i])
total=(oddsum * 3) + evensum
check = int(10 - math.ceil(total % 10.0)) %10
if check != int(eancode[-1]):
return False
return True
class res_users(osv.osv):
_inherit = 'res.users'
@ -43,7 +13,7 @@ class res_users(osv.osv):
def _check_ean(self, cr, uid, ids, context=None):
return all(
check_ean(user.ean13) == True
openerp.addons.product.product.check_ean(user.ean13) == True
for user in self.browse(cr, uid, ids, context=context)
)

View File

@ -27,9 +27,6 @@ from _common import rounding
import re
from tools.translate import _
def is_pair(x):
return not x%2
def ean_checksum(eancode):
"""returns the checksum of an ean string of length 13, returns -1 if the string has the wrong length"""
if len(eancode) <> 13:
@ -42,7 +39,7 @@ def ean_checksum(eancode):
finalean=reversevalue[1:]
for i in range(len(finalean)):
if is_pair(i):
if i % 2 == 0:
oddsum += int(finalean[i])
else:
evensum += int(finalean[i])