L10N_CH : invoice : the bvr reference number is now checked (recursive mod10)

bzr revid: bch-43961ec80451f22594cc09527cbb48763d166af9
This commit is contained in:
bch 2007-01-17 14:46:17 +00:00
parent f861957c47
commit 2706b09f4b
1 changed files with 29 additions and 2 deletions

View File

@ -49,11 +49,38 @@ class account_invoice(osv.osv):
'dta_state': lambda *a: 'none',
}
def _mod10r(self,nbr):
"""
Input arg : account or invoice number
Output return: the same number completed with the recursive mod10
key
"""
codec=[0,9,4,6,8,2,7,1,3,5]
report = 0
result=""
for chiffre in nbr:
if not chiffre.isdigit():
continue
report = codec[ (int(chiffre) +report) % 10 ]
result += chiffre
return result + str((10-report) % 10)
# 0100054150009>132000000000000000000000014+ 1300132412>
def _check_bvr(self, cr, uid, ids):
return False
invoices = self.browse(cr,uid,ids)
for invoice in invoices:
if invoice.bvr_ref_num and self._mod10r(invoice.bvr_ref_num[:-1]) != invoice.bvr_ref_num:
print self._mod10r(invoice.bvr_ref_num[:-1])," ",invoice.bvr_ref_num
return False
return True
_constraints = [
(_check_bvr, 'Error : Invalid Bvr Number.', [''])
(_check_bvr, 'Error : Invalid Bvr Number (wrong checksum).', [''])
]