Skip to content

Commit

Permalink
[FIX] account_statement_import_sheet_file: Erroneous values taken dep…
Browse files Browse the repository at this point in the history
…ending on the amount_type
  • Loading branch information
feg-adhoc committed Dec 27, 2024
1 parent 77b3d19 commit 8391cf6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 41 deletions.
2 changes: 1 addition & 1 deletion account_statement_import_sheet_file/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand All @@ -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"]
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
<field name="amount_type" />
<field
name="amount_column"
invisible="amount_type == 'distinct_credit_debit'"
required="amount_type != 'distinct_credit_debit'"
invisible="amount_type != 'simple_value'"
required="amount_type == 'simple_value'"
/>

<field
Expand Down

0 comments on commit 8391cf6

Please sign in to comment.