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).', ['']) ]