Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] account_statement_import_txt_xlsx: empty balance_column field #703

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -61,7 +62,6 @@ def parse(self, data_file, mapping, filename):
lines = self._parse_lines(mapping, data_file, currency_code)
if not lines:
return currency_code, account_number, [{"transactions": []}]

lines = list(sorted(lines, key=lambda line: line["timestamp"]))
first_line = lines[0]
last_line = lines[-1]
Expand Down Expand Up @@ -280,12 +280,14 @@ def _decimal(column_name):
return {}

if isinstance(timestamp, str):
timestamp = datetime.strptime(timestamp, mapping.timestamp_format)
if not (timestamp == "" and description):
timestamp = datetime.strptime(timestamp, mapping.timestamp_format)

if balance:
if balance or balance == 0.0:
balance = self._parse_decimal(balance, mapping)
else:
balance = None
if not balance:
balance = 0.0

if debit_credit:
amount = amount.copy_abs()
Expand Down Expand Up @@ -434,8 +436,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
Loading