mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[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:
committed by
Rocío Vega
parent
4fc4caaf20
commit
894c42c0cb
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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:
|
||||
@@ -320,6 +325,18 @@ class AccountStatementImportSheetParser(models.TransientModel):
|
||||
else None
|
||||
)
|
||||
|
||||
debit_column = (
|
||||
self._get_values_from_column(values, columns, "amount_debit_column")
|
||||
if columns["amount_debit_column"]
|
||||
else None
|
||||
)
|
||||
|
||||
credit_column = (
|
||||
self._get_values_from_column(values, columns, "amount_credit_column")
|
||||
if columns["amount_credit_column"]
|
||||
else None
|
||||
)
|
||||
|
||||
if currency != currency_code:
|
||||
continue
|
||||
|
||||
@@ -342,7 +359,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,
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"Date","Label","Currency","Amount","Amount Currency","Partner Name","Bank Account"
|
||||
"12/15/2018","LABEL 1","USD","33.50","0.0","John Doe","123456789"
|
||||
"12/15/2018","LABEL 2","EUR","-1,525.00","-1,000.00","Azure Interior",""
|
||||
|
@@ -506,3 +506,35 @@ class TestAccountStatementImportSheetFile(common.TransactionCase):
|
||||
line4 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 4")
|
||||
self.assertEqual(line1.amount, 50)
|
||||
self.assertEqual(line4.amount, -1300)
|
||||
|
||||
def test_amount_inverse_sign(self):
|
||||
self.sample_statement_map.amount_inverse_sign = True
|
||||
journal = self.AccountJournal.create(
|
||||
{
|
||||
"name": "Bank",
|
||||
"type": "bank",
|
||||
"code": "BANK",
|
||||
"currency_id": self.currency_usd.id,
|
||||
"suspense_account_id": self.suspense_account.id,
|
||||
}
|
||||
)
|
||||
filename = "fixtures/sample_statement_credit_card_inverse_sign_en.csv"
|
||||
data = self._data_file(filename, "utf-8")
|
||||
wizard = self.AccountStatementImport.with_context(journal_id=journal.id).create(
|
||||
{
|
||||
"statement_filename": filename,
|
||||
"statement_file": data,
|
||||
"sheet_mapping_id": self.sample_statement_map.id,
|
||||
}
|
||||
)
|
||||
wizard.with_context(
|
||||
account_statement_import_sheet_file_test=True
|
||||
).import_file_button()
|
||||
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
|
||||
self.assertEqual(len(statement), 1)
|
||||
self.assertEqual(len(statement.line_ids), 2)
|
||||
line1 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 1")
|
||||
self.assertEqual(line1.amount, -33.50)
|
||||
line2 = statement.line_ids.filtered(lambda x: x.payment_ref == "LABEL 2")
|
||||
self.assertEqual(line2.amount, 1525.00)
|
||||
self.assertEqual(line2.amount_currency, 1000.00)
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
'invisible': [('amount_type', '=', 'distinct_credit_debit')],
|
||||
}"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="amount_debit_column"
|
||||
attrs="{
|
||||
@@ -103,6 +104,7 @@
|
||||
'invisible': [('amount_type', '!=', 'distinct_credit_debit')],
|
||||
}"
|
||||
/>
|
||||
<field name="amount_inverse_sign" />
|
||||
<field name="balance_column" />
|
||||
<field name="original_currency_column" />
|
||||
<field name="original_amount_column" />
|
||||
|
||||
Reference in New Issue
Block a user