[FIX] l10n_fr_certification: py3 json.dumps typo
In python3 json.dumps acts differently: - encoding parameter is not available - output is unicode (in python 2 it was bytestring if only ascii or unicode otherwise) This commit adapt string types so getting hash for the certifications works for python2 and python3 by having unicode up to the sha. Since ensure_ascii is set on json.dumps, these things are not risky since uncode and bytestring can be combined without encoding error. opw-804561 closes #22301
This commit is contained in:
@@ -36,13 +36,13 @@ class AccountMove(models.Model):
|
||||
_('An error occured when computing the inalterability. Impossible to get the unique previous posted journal entry.'))
|
||||
|
||||
#build and return the hash
|
||||
return self._compute_hash(prev_move.l10n_fr_hash if prev_move else '')
|
||||
return self._compute_hash(prev_move.l10n_fr_hash if prev_move else u'')
|
||||
|
||||
def _compute_hash(self, previous_hash):
|
||||
""" Computes the hash of the browse_record given as self, based on the hash
|
||||
of the previous record in the company's securisation sequence given as parameter"""
|
||||
self.ensure_one()
|
||||
hash_string = sha256(previous_hash + self.l10n_fr_string_to_hash)
|
||||
hash_string = sha256((previous_hash + self.l10n_fr_string_to_hash).encode('utf-8'))
|
||||
return hash_string.hexdigest()
|
||||
|
||||
def _compute_string_to_hash(self):
|
||||
@@ -63,7 +63,7 @@ class AccountMove(models.Model):
|
||||
values[k] = _getattrstring(line, field)
|
||||
#make the json serialization canonical
|
||||
# (https://tools.ietf.org/html/draft-staykov-hu-json-canonical-form-00)
|
||||
move.l10n_fr_string_to_hash = dumps(values, sort_keys=True, encoding="utf-8",
|
||||
move.l10n_fr_string_to_hash = dumps(values, sort_keys=True,
|
||||
ensure_ascii=True, indent=None,
|
||||
separators=(',',':'))
|
||||
|
||||
@@ -118,7 +118,7 @@ class AccountMove(models.Model):
|
||||
|
||||
if not moves:
|
||||
raise UserError(_('There isn\'t any journal entry flagged for data inalterability yet for the company %s. This mechanism only runs for journal entries generated after the installation of the module France - Certification CGI 286 I-3 bis.') % self.env.user.company_id.name)
|
||||
previous_hash = ''
|
||||
previous_hash = u''
|
||||
start_move_info = []
|
||||
for move in moves:
|
||||
if move.l10n_fr_hash != move._compute_hash(previous_hash=previous_hash):
|
||||
|
||||
Reference in New Issue
Block a user