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: Wrong bank_ac_no filter + simplify logic in automatch #45129

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

marination
Copy link
Collaborator

@marination marination commented Jan 7, 2025

Closes alyf-de/banking#135

Issue

File "apps/erpnext/erpnext/accounts/doctype/bank_transaction/auto_match_party.py", line 58, in match_account_in_party
    party_result = frappe.db.get_all(
  File "apps/frappe/frappe/database/database.py", line 810, in get_all
    return frappe.get_all(*args, **kwargs)
  File "apps/frappe/frappe/__init__.py", line 1938, in get_all
    return get_list(doctype, *args, **kwargs)
  File "apps/frappe/frappe/__init__.py", line 1910, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
  File "apps/frappe/frappe/model/db_query.py", line 190, in execute
    result = self.build_and_run()
  File "apps/frappe/frappe/model/db_query.py", line 231, in build_and_run
    return frappe.db.sql(
  File "apps/frappe/frappe/database/database.py", line 244, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 563, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 825, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1199, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1054, "Unknown column 'tabBank Account.bank_ac_no' in 'where clause'")
  • or_filters["bank_ac_no"] gets set for "Employee" and then when the loop moves on to the next party type, this value persists, since or_filters is instantiated outside the loop and does not get refreshed
  • The loop is unnecessary as Supplier and Customer do not have any data to extract and match here

Fix

  • Simplify the logic (Look in Bank Account first and then Employee) and remove the loop (we were checking in "Bank Account" in every loop which was plain ... futile)
  • Return fast if filter data is unavailable
  • Misc: Sourcery refactors

Already has tests that should check correctness

To Test

  • Create a Bank account and an IBAN to it "DE123456789" and set a party and party type in it
  • In Accounts Settings > Banking > enable automatic party matching
  • Create a Bank Transaction and set the Party IBAN as "DE123456789"
  • Submit the transaction > The Party must be set
  • The same thing can be achieved by setting the IBAN in the "Employee" doctype (remove party from bank account)

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Jan 7, 2025
@marination marination removed the needs-tests This PR needs automated unit-tests. label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unknown column 'tabBank Account.bank_ac_no'
1 participant