[IMP] account_statement_import_txt_xlsx: wizard: 2 amount columns, for IN and OUT

[IMP] account_statement_import_txt_xlsx: wizard: amount2_reverse boolean field, with tests
This commit is contained in:
Henrik Norlin
2022-04-03 15:06:07 +02:00
committed by Rocío Vega
parent 2683695163
commit ddcd036186
7 changed files with 95 additions and 2 deletions

View File

@@ -66,6 +66,14 @@ class AccountStatementImportSheetMapping(models.Model):
required=True,
help="Amount of transaction in journal's currency",
)
amount2_column = fields.Char(
string="Amount2 column",
help="Some statements have two amount columns, for IN and OUT",
)
amount2_reverse = fields.Boolean(
string="Amount2 reverse +/-",
help="If there are positive numbers for money going OUT, reverse +/-",
)
balance_column = fields.Char(
help="Balance after transaction in journal's currency",
)

View File

@@ -113,6 +113,9 @@ class AccountStatementImportSheetParser(models.TransientModel):
header.index(mapping.currency_column) if mapping.currency_column else None
)
columns["amount_column"] = header.index(mapping.amount_column)
columns["amount2_column"] = (
header.index(mapping.amount2_column) if mapping.amount2_column else None
)
columns["balance_column"] = (
header.index(mapping.balance_column) if mapping.balance_column else None
)
@@ -189,7 +192,13 @@ class AccountStatementImportSheetParser(models.TransientModel):
if columns["currency_column"] is not None
else currency_code
)
amount = values[columns["amount_column"]]
factor = -1 if mapping["amount2_reverse"] else 1
if values[columns["amount_column"]] in (False, "", "0.00"):
amount = values[columns["amount2_column"]]
amount = factor * self._parse_decimal(amount, mapping)
else:
amount = values[columns.get("amount_column")]
amount = self._parse_decimal(amount, mapping)
balance = (
values[columns["balance_column"]]
if columns["balance_column"] is not None
@@ -252,7 +261,6 @@ class AccountStatementImportSheetParser(models.TransientModel):
if isinstance(timestamp, str):
timestamp = datetime.strptime(timestamp, mapping.timestamp_format)
amount = self._parse_decimal(amount, mapping)
if balance:
balance = self._parse_decimal(balance, mapping)
else: