diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 5ec7a803ab8..2c3ff5149d6 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -7,7 +7,6 @@ from odoo.tools.misc import formatLang, format_date from datetime import date, timedelta from itertools import groupby -from stdnum.iso7064 import mod_97_10 from itertools import zip_longest from hashlib import sha256 from json import dumps @@ -24,6 +23,15 @@ INTEGRITY_HASH_MOVE_FIELDS = ('date', 'journal_id', 'company_id') INTEGRITY_HASH_LINE_FIELDS = ('debit', 'credit', 'account_id', 'partner_id') +def calc_check_digits(number): + """Calculate the extra digits that should be appended to the number to make it a valid number. + Source: python-stdnum iso7064.mod_97_10.calc_check_digits + """ + number_base10 = ''.join(str(int(x, 36)) for x in number) + checksum = int(number_base10) % 97 + return '%02d' % ((98 - 100 * checksum) % 97) + + class AccountMove(models.Model): _name = "account.move" _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin'] @@ -1679,7 +1687,7 @@ class AccountMove(models.Model): """ self.ensure_one() base = self.id - check_digits = mod_97_10.calc_check_digits('{}RF'.format(base)) + check_digits = calc_check_digits('{}RF'.format(base)) reference = 'RF{} {}'.format(check_digits, " ".join(["".join(x) for x in zip_longest(*[iter(str(base))]*4, fillvalue="")])) return reference @@ -1698,7 +1706,7 @@ class AccountMove(models.Model): partner_ref = self.partner_id.ref partner_ref_nr = re.sub('\D', '', partner_ref or '')[-21:] or str(self.partner_id.id)[-21:] partner_ref_nr = partner_ref_nr[-21:] - check_digits = mod_97_10.calc_check_digits('{}RF'.format(partner_ref_nr)) + check_digits = calc_check_digits('{}RF'.format(partner_ref_nr)) reference = 'RF{} {}'.format(check_digits, " ".join(["".join(x) for x in zip_longest(*[iter(partner_ref_nr)]*4, fillvalue="")])) return reference