Skip to content

Commit 0718f8f

Browse files
committed
refactor: use extend_doctype_class instead of override_doctype_class
1 parent ccea589 commit 0718f8f

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bench --site [sitename] uninstall-app banking
8282
- `unpaid_vouchers.py`: Payment Entry/Journal Entry creation
8383

8484
**`banking/overrides/`** - ERPNext DocType customizations
85-
- `bank_transaction.py`: Enhanced reconciliation validation (CustomBankTransaction)
85+
- `bank_transaction.py`: Enhanced reconciliation validation (`CustomBankTransaction`, mixed in via `extend_doctype_class`)
8686
- `bank_account.py`: IBAN validation hooks
8787

8888
**`banking/connectors/`** - External service communication
@@ -174,7 +174,7 @@ Tests run against ERPNext's shipped `_Test Company` (INR). Inherit from `frappe.
174174

175175
### Hooks Configuration
176176
Key hooks in `hooks.py`:
177-
- `override_doctype_class`: Replace Bank Transaction with CustomBankTransaction
177+
- `extend_doctype_class`: Mix `CustomBankTransaction` into Bank Transaction (preferred over `override_doctype_class` in v16+)
178178
- `doc_events`: Validation and status change hooks
179179
- `bank_reconciliation_doctypes`: Register Bank Transaction for reconciliation
180180
- `get_matching_queries`: Point to custom matching logic

banking/hooks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@
101101

102102
# DocType Class
103103
# ---------------
104-
# Override standard doctype classes
104+
# Extend standard doctype classes
105105

106-
override_doctype_class = {"Bank Transaction": "banking.overrides.bank_transaction.CustomBankTransaction"}
106+
extend_doctype_class = {
107+
"Bank Transaction": ["banking.overrides.bank_transaction.CustomBankTransaction"],
108+
}
107109

108110
# Document Events
109111
# ---------------

banking/overrides/bank_transaction.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010

1111
class CustomBankTransaction(BankTransaction):
12+
"""Mixin applied to **Bank Transaction** via the `extend_doctype_class` hook.
13+
14+
Inherits from `BankTransaction` so type checkers and IDEs can resolve all
15+
DocType fields and inherited methods. At runtime Frappe builds a class
16+
`ExtendedBankTransaction(CustomBankTransaction, BankTransaction)`; the
17+
resulting MRO is well-defined (classic diamond) and `super()` calls from
18+
this mixin still chain into the original `BankTransaction` methods.
19+
"""
20+
1221
def before_validate(self):
1322
"""Normalize imported signs before ERPNext computes fees and balances.
1423

0 commit comments

Comments
 (0)