Skip to content

Commit

Permalink
[FIX] empty balance_column field
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Amaral committed Jun 20, 2024
1 parent 11e18fa commit 518f194
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import itertools
import logging
import re
from datetime import datetime
from decimal import Decimal
from io import StringIO
Expand Down Expand Up @@ -434,8 +435,16 @@ def _parse_decimal(self, value, mapping):
if isinstance(value, Decimal):
return value
elif isinstance(value, float):
return Decimal(value)
return Decimal(str(value))
thousands, decimal = mapping._get_float_separators()
# Remove all characters except digits, thousands separator,
# decimal separator, and signs
value = (
re.sub(
r"[^\d\-+" + re.escape(thousands) + re.escape(decimal) + "]+", "", value
)
or "0"
)
value = value.replace(thousands, "")
value = value.replace(decimal, ".")
return Decimal(value)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2019 ForgeFlow, S.L.
# Copyright 2020 CorporateHub (https://corporatehub.eu)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import decimal
from base64 import b64encode
from os import path

Expand Down Expand Up @@ -516,7 +515,7 @@ def test_skip_empty_lines(self):
"sheet_mapping_id": self.sample_statement_map.id,
}
)
with self.assertRaises(decimal.InvalidOperation):
with self.assertRaises(ValueError):
wizard.with_context(
account_statement_import_txt_xlsx_test=True
).import_file_button()
Expand Down

0 comments on commit 518f194

Please sign in to comment.