From 2706b09f4b27481d206dfa982fbf0d0c43bb2d0a Mon Sep 17 00:00:00 2001 From: bch <> Date: Wed, 17 Jan 2007 14:46:17 +0000 Subject: [PATCH] L10N_CH : invoice : the bvr reference number is now checked (recursive mod10) bzr revid: bch-43961ec80451f22594cc09527cbb48763d166af9 --- addons/l10n_ch/dta/invoice.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/l10n_ch/dta/invoice.py b/addons/l10n_ch/dta/invoice.py index 8af850ef6c2..c228c1b5511 100644 --- a/addons/l10n_ch/dta/invoice.py +++ b/addons/l10n_ch/dta/invoice.py @@ -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).', ['']) ]