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 (backport #45129) #45402

Closed

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jan 23, 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)
    This is an automatic backport of pull request fix: Wrong bank_ac_no filter + simplify logic in automatch #45129 done by Mergify.

(cherry picked from commit 8521796)

# Conflicts:
#	erpnext/accounts/doctype/bank_transaction/auto_match_party.py
Copy link
Contributor Author

mergify bot commented Jan 23, 2025

Cherry-pick of 8521796 has failed:

On branch mergify/bp/version-15-hotfix/pr-45129
Your branch is up to date with 'origin/version-15-hotfix'.

You are currently cherry-picking commit 8521796811.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   erpnext/accounts/doctype/bank_transaction/auto_match_party.py

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

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

Successfully merging this pull request may close these issues.

1 participant