diff --git a/account_statement_import_sheet_file/__manifest__.py b/account_statement_import_sheet_file/__manifest__.py
index 547ab87b5..f32e012ee 100644
--- a/account_statement_import_sheet_file/__manifest__.py
+++ b/account_statement_import_sheet_file/__manifest__.py
@@ -5,7 +5,7 @@
{
"name": "Bank Statement TXT/CSV/XLSX Import",
"summary": "Import TXT/CSV or XLSX files as Bank Statements in Odoo",
- "version": "17.0.1.1.0",
+ "version": "17.0.1.2.0",
"category": "Accounting",
"website": "https://github.com/OCA/bank-statement-import",
"author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)",
diff --git a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py
index cc7875ba2..af66d423e 100644
--- a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py
+++ b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py
@@ -191,9 +191,20 @@ def _parse_lines(self, mapping, data_file, currency_code):
if mapping.offset_column:
header = header[mapping.offset_column :]
- # NOTE no seria necesario debit_column y credit_column ya que tenemos los
- # respectivos campos related
- for column_name in self._get_column_names():
+ # We remove the column_name depending on the amount_type
+ # so that it doesn't iterate through them in case the specific option is not selected.
+
+ column_names = self._get_column_names()
+
+ remove_map = {
+ 'simple_value': ["amount_debit_column", "amount_credit_column", "debit_credit_column"],
+ 'distinct_credit_debit': ["amount_column", "debit_credit_column"],
+ 'absolute_value': ["amount_credit_column", "amount_debit_column", "amount_column"],
+ }
+
+ column_names = [col for col in column_names if col not in remove_map.get(mapping.amount_type, [])]
+
+ for column_name in column_names:
columns[column_name] = self._get_column_indexes(
header, column_name, mapping
)
@@ -266,12 +277,15 @@ def _decimal(column_name, values):
self._get_values_from_column(values, columns, column_name),
mapping,
)
-
- amount = _decimal("amount_column", values)
- if not amount:
- amount = abs(_decimal("amount_debit_column", values) or 0)
- if not amount:
- amount = -abs(_decimal("amount_credit_column", values) or 0)
+ # We set an specific amount depending the amount_type
+ if mapping.amount_type == 'simple_value':
+ amount = _decimal("amount_column", values)
+ elif mapping.amount_type == 'distinct_credit_debit':
+ credit = abs(_decimal("amount_credit_column", values) or 0)
+ debit = abs(_decimal("amount_debit_column", values) or 0)
+ amount = -(credit - debit)
+ elif mapping.amount_type == "absolute_value":
+ amount = abs(_decimal("debit_credit_column", values) or 0)
balance = (
self._get_values_from_column(values, columns, "balance_column")
@@ -290,11 +304,6 @@ def _decimal(column_name, values):
if columns["original_amount_column"]
else None
)
- debit_credit = (
- self._get_values_from_column(values, columns, "debit_credit_column")
- if columns["debit_credit_column"]
- else None
- )
transaction_id = (
self._get_values_from_column(values, columns, "transaction_id_column")
if columns["transaction_id_column"]
@@ -331,18 +340,6 @@ def _decimal(column_name, values):
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
@@ -354,18 +351,6 @@ def _decimal(column_name, values):
else:
balance = None
- if debit_credit is not None:
- amount = abs(amount)
- if debit_credit == mapping.debit_value:
- amount = -amount
-
- if debit_column and credit_column:
- debit_amount = self._parse_decimal(debit_column, mapping)
- debit_amount = abs(debit_amount)
- credit_amount = self._parse_decimal(credit_column, mapping)
- credit_amount = abs(credit_amount)
- amount = -(credit_amount - debit_amount)
-
if original_amount:
original_amount = math.copysign(
self._parse_decimal(original_amount, mapping), amount
diff --git a/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml b/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml
index 7418b4d11..07872e6fd 100644
--- a/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml
+++ b/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml
@@ -78,8 +78,8 @@