[IMP] point_of_sale: Add the EAN13 field on the user with validation
bzr revid: stw@openerp.com-20120509093517-24lw0pbiqum0wpw1
This commit is contained in:
parent
f638ce36cf
commit
ca2db3740e
|
@ -22,6 +22,7 @@
|
|||
import point_of_sale
|
||||
import account_bank_statement
|
||||
import product
|
||||
import res_users
|
||||
import wizard
|
||||
import report
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ Main features :
|
|||
'account_statement_view.xml',
|
||||
'account_statement_report.xml',
|
||||
'product_view.xml',
|
||||
'res_users_view.xml',
|
||||
],
|
||||
'demo_xml': [
|
||||
'point_of_sale_demo.xml',
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
from osv import osv, fields
|
||||
import math
|
||||
|
||||
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'
|
||||
|
||||
_columns = {
|
||||
'ean13' : fields.char('EAN13', size=13, help="BarCode"),
|
||||
}
|
||||
|
||||
def _check_ean(self, cr, uid, ids, context=None):
|
||||
return all(
|
||||
check_ean(user.ean13) == True
|
||||
for user in self.browse(cr, uid, ids, context=context)
|
||||
)
|
||||
|
||||
_constraints = [
|
||||
(_check_ean, "Error: Invalid ean code", ['ean13'],),
|
||||
]
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="res_users_form_view" model="ir.ui.view">
|
||||
<field name="name">res.users.form.view</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="base.view_users_form" />
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="Point Of Sale">
|
||||
<field name="ean13" />
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue