Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bank Statement Import Error When Balance Equals 0 on any row #761

Open
DavidAureatic opened this issue Jan 22, 2025 · 0 comments
Open

Bank Statement Import Error When Balance Equals 0 on any row #761

DavidAureatic opened this issue Jan 22, 2025 · 0 comments
Labels

Comments

@DavidAureatic
Copy link

Error while importing an XLXS file whith field balance 0 on any row
The error given is "This bank statement file format is not supported. Did you install the Odoo module to support this format?"
This is a generic error typically raised when the file mapping is incorrect. However, the customer was successfully importing files for a year before this issue was detected. and it happens because a row with 0 value on field balance of the XLSX file.

Module 15.0

bank-statement-import/account_statement_import_txt_xlsx
file: account_statement_import_sheet_parser.py
method: _parse_rows
Code Snippet (line 256):
if balance:
balance = self._parse_decimal(balance, mapping)
else:
balance = None

Describe the bug

When parsing the file, if the balance field contains a value of 0, the condition if balance: evaluates to False. Consequently, the code enters the else block, setting the balance to None. However, a balance of 0 is valid, and this causes the object to be malformed, leading to the generic error.

This issue was encountered when the customer set a bank account's balance to 0 as part of a valid movement.

To Reproduce

Affected versions:
15.0
16.0

Steps to reproduce the behavior:
1.- Create a bank statement with a row where the balance is 0. For example:

Row 1: Amount: 100, Balance: 200
Row 2: Amount: -200, Balance: 0

2.- Import the file.
3.- Observe that the generic error is raised.

Expected behavior
The balance field with a value of 0 should be correctly parsed as a valid value.

Additional context
Solution?
Line 193 already accounts for cases where the balance field is not defined on xlsx file, setting it to None:

balance = (
values[columns["balance_column"]]
if columns["balance_column"] is not None
else None
)
Since 0 is a valid value, the condition should check if the balance is explicitly None, as shown below:

if balance is not None:
balance = self._parse_decimal(balance, mapping)
else:
balance = None

hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant