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

fix: AttributeError in Bank Statement Import (backport #40494) #40499

Merged
merged 2 commits into from
Mar 17, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 17, 2024

This issue is a combination of 2 different bugs.

  1. refactor: disallow bank transactions on different currencies #39336 A bug in a recently added validation on Bank Transaction currency
  2. A dormant initialization bug in Bank Statement Import

Scenario on which error occur

This 'AttributeError' only shows up if there were any errors during import, which now it does due to [1] above.
Now, when you retry the import, you'll get the AttributeError due to the uninitialized 'payload_count'.

Cause

'Bank Statement Import' inherits 'Data Import', which has 'payload_count' attribute.
But, It looks like 'Bank Statment Import' is not properly initializing 'Data Import' fields[2]. Since, the Importer class heavly relies on the object being of class 'Data Import', any missing attributes of that class causes hard to debug issues like this.

Traceback with variables (most recent call last):
  File "apps/erpnext/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py", line 159, in start_import
    i.import_data()
      data_import = <BankStatementImport: Bank Statement Import on 2024-03-17 06:36:39.938968>
      bank_account = 'Feynman Acc - HDFC'
      import_file_path = '/files/Bank Transaction.csv'
      google_sheets_url = None
      bank = 'HDFC'
      template_options = '{"column_to_field_map": {"7": "name"}}'
      file = '/files/Bank Transaction.csv'
      import_file = <frappe.core.doctype.data_import.importer.ImportFile object at 0x109663af0>
      data = [['Date', 'Deposit', 'Withdrawal', 'Description', 'Reference Number', 'Bank Account', 'Currency'], ['2024-02-08', '1344', None, None, 'POS Invoice 1', 'Feynman Acc - HDFC', 'INR']]
      i = <frappe.core.doctype.data_import.importer.Importer object at 0x109663370>
  File "apps/frappe/frappe/core/doctype/data_import/importer.py", line 105, in import_data
    if self.data_import.status == "Partial Success" and len(import_log) >= self.data_import.payload_count:
      self = <frappe.core.doctype.data_import.importer.Importer object at 0x109663370>
      payloads = [{'doc': {'naming_series': 'ACC-BTN-.YYYY.-', 'date': datetime.datetime(2024, 2, 8, 0, 0), 'status': 'Pending', 'bank_account': 'Feynman Acc - HDFC', 'company': 'Lisp 2', 'amended_from': None, 'deposit': 1344.0, 'withdrawal': None, 'currency': 'INR', 'description': None, 'reference_number': 'POS Invoice 1', 'transaction_id': None, 'transaction_type': None, 'allocated_amount': None, 'unallocated_amount': None, 'party_type': None, 'party': None, 'bank_party_name': None, 'bank_party_account_number': None, 'bank_party_iban': None, '__unsaved': 1}, 'rows': [<frappe.core.doctype.data_import.importer.Row object at 0x1099ee620>]}]
      warnings = []
      import_log = [{'row_indexes': '[2]', 'success': 1, 'log_index': 0}]
      log_index = 0
builtins.AttributeError: 'BankStatementImport' object has no attribute 'payload_count'

This is an automatic backport of pull request #40494 done by [Mergify](https://mergify.com).

@mergify mergify bot requested a review from deepeshgarg007 as a code owner March 17, 2024 02:23
@mergify mergify bot requested a review from ruthra-kumar as a code owner March 17, 2024 02:23
@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Mar 17, 2024
@ruthra-kumar ruthra-kumar merged commit be730fe into version-15-hotfix Mar 17, 2024
12 checks passed
@ruthra-kumar ruthra-kumar deleted the mergify/bp/version-15-hotfix/pr-40494 branch March 17, 2024 02:40
@frappe-pr-bot
Copy link
Collaborator

🎉 This PR is included in version 15.17.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-tests This PR needs automated unit-tests. released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants