Merge PR #663 into 16.0

Signed-off-by alexey-pelykh
This commit is contained in:
OCA-git-bot
2024-02-06 10:04:46 +00:00
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,

View File

@@ -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",""
1 Date Label Currency Amount Amount Currency Partner Name Bank Account
2 12/15/2018 LABEL 1 USD 33.50 0.0 John Doe 123456789
3 12/15/2018 LABEL 2 EUR -1,525.00 -1,000.00 Azure Interior

View File

@@ -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)

View File

@@ -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" />