From 0b22bdefaab2888a855ff7614fc81638366b8aaf Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 25 Aug 2023 01:11:36 +0530 Subject: [PATCH] feat: 'Name in Description' added to rank and match reason - misc: avoid null party value matches - misc: unset hidden filter fields --- .pre-commit-config.yaml | 34 +++++++++---------- .../bank_reconciliation_tool_beta.py | 30 +++++++++++----- .../actions_panel.js | 1 + 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0d6cc58343e..2c9a60c7c4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,23 +16,23 @@ repos: - id: check-merge-conflict - id: check-ast - # - repo: https://github.com/pre-commit/mirrors-eslint - # rev: v8.44.0 - # hooks: - # - id: eslint - # types_or: [javascript] - # args: ['--quiet'] - # # Ignore any files that might contain jinja / bundles - # exclude: | - # (?x)^( - # erpnext/public/dist/.*| - # cypress/.*| - # .*node_modules.*| - # .*boilerplate.*| - # erpnext/public/js/controllers/.*| - # erpnext/templates/pages/order.js| - # erpnext/templates/includes/.* - # )$ + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v8.44.0 + hooks: + - id: eslint + types_or: [javascript] + args: ['--quiet'] + # Ignore any files that might contain jinja / bundles + exclude: | + (?x)^( + erpnext/public/dist/.*| + cypress/.*| + .*node_modules.*| + .*boilerplate.*| + erpnext/public/js/controllers/.*| + erpnext/templates/pages/order.js| + erpnext/templates/includes/.* + )$ - repo: https://github.com/PyCQA/flake8 rev: 6.0.0 diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py b/erpnext/accounts/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py index e9d526cdf1b..f4a11bb3f64 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py @@ -311,9 +311,17 @@ def check_matching( as_dict=1, ) ) - return ( - sorted(matching_vouchers, key=lambda x: x["rank"], reverse=True) if matching_vouchers else [] - ) + + if not matching_vouchers: + return [] + + for voucher in matching_vouchers: + # higher rank if voucher name is in bank transaction + if voucher["name"] in transaction.description: + voucher["rank"] += 1 + voucher["name_in_desc_match"] = 1 + + return sorted(matching_vouchers, key=lambda x: x["rank"], reverse=True) def get_queries( @@ -439,7 +447,9 @@ def get_bt_matching_query(exact_match, transaction, exact_party_match): # same bank account must have same company and currency field = "deposit" if transaction.withdrawal > 0.0 else "withdrawal" filter_by_party = ( - "AND party_type = %(party_type)s AND party = %(party)s" if exact_party_match else "" + "AND party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL" + if exact_party_match + else "" ) return f""" @@ -447,7 +457,7 @@ def get_bt_matching_query(exact_match, transaction, exact_party_match): ( CASE WHEN reference_number = %(reference_no)s THEN 1 ELSE 0 END + CASE WHEN {field} = %(amount)s THEN 1 ELSE 0 END - + CASE WHEN ( party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END + + CASE WHEN ( party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL) THEN 1 ELSE 0 END + CASE WHEN unallocated_amount = %(amount)s THEN 1 ELSE 0 END + 1 ) AS rank, @@ -467,7 +477,7 @@ def get_bt_matching_query(exact_match, transaction, exact_party_match): CASE WHEN {field} = %(amount)s THEN 1 ELSE 0 END ) as amount_match, ( - CASE WHEN ( party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END + CASE WHEN ( party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL) THEN 1 ELSE 0 END ) as party_match, ( CASE WHEN unallocated_amount = %(amount)s THEN 1 ELSE 0 END @@ -596,13 +606,15 @@ def get_pe_matching_query( filter_by_reference_no = f"AND reference_no = '{transaction.reference_number}'" filter_by_party = ( - "AND (party_type = %(party_type)s AND party = %(party)s )" if exact_party_match else "" + "AND (party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL)" + if exact_party_match + else "" ) return f""" SELECT (CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END - + CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END + + CASE WHEN (party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL) THEN 1 ELSE 0 END + CASE WHEN paid_amount = %(amount)s THEN 1 ELSE 0 END + 1 ) AS rank, 'Payment Entry' as doctype, @@ -615,7 +627,7 @@ def get_pe_matching_query( posting_date, {currency_field}, (CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END) AS reference_number_match, - (CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END) AS party_match, + (CASE WHEN (party_type = %(party_type)s AND party = %(party)s AND party IS NOT NULL) THEN 1 ELSE 0 END) AS party_match, (CASE WHEN paid_amount = %(amount)s THEN 1 ELSE 0 END) AS amount_match FROM `tabPayment Entry` diff --git a/erpnext/public/js/bank_reconciliation_tool_beta/actions_panel.js b/erpnext/public/js/bank_reconciliation_tool_beta/actions_panel.js index 2dc7eb8657f..eb21acafd69 100644 --- a/erpnext/public/js/bank_reconciliation_tool_beta/actions_panel.js +++ b/erpnext/public/js/bank_reconciliation_tool_beta/actions_panel.js @@ -148,6 +148,7 @@ erpnext.accounts.bank_reconciliation.ActionsPanel = class ActionsPanel { "Party": row.party_match || 0, "Transaction Amount": row.amount_match || 0, "Unallocated Amount": row.unallocated_amount_match || 0, + "Name in Description": row.name_in_desc_match || 0, } return [ this.help_button(row.name),