Skip to content

Bank Reconciliation Rule Preview & Filter Preset#366

Open
0xD0M1M0 wants to merge 7 commits into
alyf-de:version-15-hotfixfrom
0xD0M1M0:bank-rule-filter-preview
Open

Bank Reconciliation Rule Preview & Filter Preset#366
0xD0M1M0 wants to merge 7 commits into
alyf-de:version-15-hotfixfrom
0xD0M1M0:bank-rule-filter-preview

Conversation

@0xD0M1M0
Copy link
Copy Markdown
Contributor

Proposed solution for #359

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 15, 2026

Greptile Summary

This PR adds two related features to Bank Reconciliation Rules: (1) a "Create Reconciliation Rule" menu item on the Bank Transaction form that pre-populates filters from the transaction's field values, and (2) an inline match-count preview panel and "Open Matches" navigation button on the Bank Reconciliation Rule form backed by a new get_bank_transaction_match_stats whitelisted endpoint.

  • bank_transaction.js (new): Adds RuleCreationDialogManager that lets users pick fields from the current transaction, then routes to a new rule form with those filters pre-loaded via frappe.route_options.
  • bank_reconciliation_rule.js: Adds BankReconciliationRuleStatsManager for the live stats preview; filters are applied to the UI using frappe.run_serially + add_filter to correctly handle async rendering and the submitted-doc read-only state.
  • bank_reconciliation_rule.py: New get_bank_transaction_match_stats endpoint with get_filter-based normalisation and explicit doctype guard; validate_filters now handles malformed JSON gracefully. Tests cover the two time windows and the bank-account mismatch guard.

Confidence Score: 4/5

Safe to merge with the filter-deduplication fix applied; the core matching and stats-count logic is correct, and the only incorrect behaviour is confined to the Open Matches list-navigation button when a rule uses two conditions on the same field.

The Open Matches button silently discards any filter row whose fieldname has already appeared, so the resulting list view shows a broader set of transactions than the rule actually matches. All other paths are well-implemented and tested.

banking/klarna_kosma_integration/doctype/bank_reconciliation_rule/bank_reconciliation_rule.js — specifically the filters_to_route_options static method

Important Files Changed

Filename Overview
banking/custom/bank_transaction.js New file adding a 'Create Reconciliation Rule' menu item to the Bank Transaction form. Permission checks, HTML escaping, and frappe.route_options usage are all correct.
banking/hooks.py One-line addition registering bank_transaction.js in doctype_js. Straightforward and correct.
banking/klarna_kosma_integration/doctype/bank_reconciliation_rule/bank_reconciliation_rule.js Adds BankReconciliationRuleStatsManager for inline match-count preview and 'Open Matches' navigation. The filters_to_route_options helper silently drops multi-condition filters for the same field, causing the Open Matches list view to show transactions that don't fully satisfy range-based rules.
banking/klarna_kosma_integration/doctype/bank_reconciliation_rule/bank_reconciliation_rule.py Adds get_bank_transaction_match_stats whitelisted endpoint with proper permission check, doctype validation, and JSON error handling. Also improves validate_filters to gracefully handle malformed JSON.
banking/klarna_kosma_integration/doctype/bank_reconciliation_rule/test_bank_reconciliation_rule.py Adds tests for the stats endpoint including time-window assertions and bank-account mismatch validation. The mock-patched today() and manual docstatus insertion pattern are correct.

Sequence Diagram

sequenceDiagram
    participant BT as Bank Transaction Form
    participant Dialog as RuleCreationDialog
    participant BRR as BankReconciliationRule Form
    participant Stats as StatsManager
    participant Server as get_bank_transaction_match_stats

    BT->>Dialog: Click Create Reconciliation Rule
    Dialog->>Dialog: show() render field checkboxes
    Dialog->>BRR: "frappe.route_options = {bank_account, filters}"
    Note over Dialog,BRR: frappe.set_route Form BRR new

    BRR->>BRR: refresh() route_options applied by Frappe router
    BRR->>BRR: render_bt_filters() FilterGroup + run_serially add_filter
    BRR->>Stats: mount(parent) fetch_and_show()
    Stats->>Server: frappe.call get_bank_transaction_match_stats
    Server-->>Stats: "{last_30_days, last_12_months, as_of}"
    Stats-->>BRR: render counts inline

    BRR->>BRR: User clicks Open Matches
    BRR->>BRR: filters_to_route_options drops 2nd+ condition per field
    BRR->>BT: frappe.set_route List Bank Transaction with flat route_options
Loading

Fix All in Cursor

Reviews (4): Last reviewed commit: "feat: create separate class" | Re-trigger Greptile

@0xD0M1M0 0xD0M1M0 changed the title Bank Reconciliation Rule Filter Preview Bank Reconciliation Rule Preview & Filter Preset May 15, 2026
Comment thread banking/custom/bank_transaction.js Outdated
Comment thread banking/custom/bank_transaction.js
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.

2 participants