[IMP] account_statement_import_sheet_file: add field amount_inverse_sign_column.

In some cases such as in credit card statements the amounts are expressed in the inverse sign.
By setting this flag during the upload the amounts will be inverted in sign.
This commit is contained in:
Jordi Ballester Alomar
2024-01-31 09:55:38 +01:00
parent f435a55b2a
commit cccf2056f1
5 changed files with 54 additions and 3 deletions

View File

@@ -79,6 +79,13 @@ class AccountStatementImportSheetMapping(models.Model):
string="Credit amount column",
help="Credit amount of transaction in journal's currency",
)
amount_inverse_sign = fields.Boolean(
string="Inverse sign of amount",
help="In some cases such as in credit card statements the "
"amounts are expressed in the inverse sign. "
"By setting this flag during the upload the amounts "
"will be inverted in sign.",
)
balance_column = fields.Char(
help="Balance after transaction in journal's currency",
)

View File

@@ -4,6 +4,7 @@
import itertools
import logging
from collections.abc import Iterable
from datetime import datetime
from decimal import Decimal
from io import StringIO
@@ -97,7 +98,11 @@ class AccountStatementImportSheetParser(models.TransientModel):
def _get_column_indexes(self, header, column_name, mapping):
column_indexes = []
if mapping[column_name] and "," in mapping[column_name]:
if (
mapping[column_name]
and isinstance(mapping[column_name], Iterable)
and "," in mapping[column_name]
):
# We have to concatenate the values
column_names_or_indexes = mapping[column_name].split(",")
else:
@@ -319,7 +324,6 @@ class AccountStatementImportSheetParser(models.TransientModel):
if columns["bank_account_column"]
else None
)
if currency != currency_code:
continue
@@ -342,7 +346,10 @@ class AccountStatementImportSheetParser(models.TransientModel):
).copy_sign(amount)
else:
original_amount = 0.0
if mapping.amount_inverse_sign:
amount = -amount
original_amount = -original_amount
balance = -balance if balance is not None else balance
line = {
"timestamp": timestamp,
"amount": amount,