[FIX] account: do not use optional library
stdnum is not a mandatory dependency It is often present as required to install the base_vat module but having a system with account without the dependency should be possible. As the calc_check_digits is pretty small, it is easy to extract Forward port of 6091be6556d to 13.0 closes odoo/odoo#40265 X-original-commit: ef245e14730e5c4858b81adfbe7e309631688663 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user