Following a suggestion by @peterg …
… I am attempting to use override_doctype_class
for the first time. It seems to be completely ignored.
My app directory:
.
├── config
├── docs
├── myApp
: : :
├── hooks.py
├── overrides
│ └── sales_invoice.py
: : :
My hooks.py
:
# along with any modifications made in other Frappe apps
# override_doctype_dashboards = {
# "Task": "myApp.task.get_dashboard_data"
# }
override_doctype_class = {
'SalesInvoice': 'app.overrides.sales_invoice.CustomSalesInvoice'
}
My overrides/sales_invoice.py
:
import frappe
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
class CustomSalesInvoice(SalesInvoice):
def before_save(self):
print(' === === === === BEFORE SAVE === === === === === ')
# super(SalesInvoice, self).on_update()
My temporarily altered erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
:
def before_save(self):
print(' *** *** *** *** BEFORE SAVE *** *** *** *** *** ')
set_account_for_mode_of_payment(self)
Resulting log file when I save changes to a draft Sales Invoice:
22:41:58 web.1 | 127.0.0.1 - - [05/Mar/2021 22:41:58] "GET / HTTP/1.0" 404 -
22:45:28 web.1 | * Detected change in '/home/erpdev/frappe-bench-DELS/apps/myApp/myApp/hooks.py', reloading
22:45:29 web.1 | * Detected change in '/home/erpdev/frappe-bench-DELS/apps/myApp/myApp/hooks.py', reloading
22:45:30 web.1 | * Restarting with inotify reloader
22:45:32 web.1 | * Debugger is active!
22:45:32 web.1 | * Debugger PIN: 105-941-064
22:45:35 web.1 | * Detected change in '/home/erpdev/frappe-bench-DELS/apps/myApp/myApp/overrides/sales_invoice.py', reloading
22:45:37 web.1 | * Restarting with inotify reloader
22:45:38 web.1 | * Debugger is active!
22:45:38 web.1 | * Debugger PIN: 105-941-064
22:46:03 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:03] "POST /api/method/frappe.desk.search.search_link HTTP/1.0" 200 -
22:46:03 web.1 | * Detected change in '/home/erpdev/frappe-bench-DELS/apps/myApp/myApp/__pycache__/hooks.cpython-38.pyc', reloading
22:46:05 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:05] "GET /api/method/frappe.desk.form.load.getdoctype?doctype=Item&with_parent=1&cached_timestamp=2021-01-25+20%3A49%3A50.222976&_=1614980205184 HTTP/1.0" 200 -
22:46:06 web.1 | * Restarting with inotify reloader
22:46:07 web.1 | * Debugger is active!
22:46:07 web.1 | * Debugger PIN: 105-941-064
22:46:14 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:14] "GET /api/method/frappe.desk.form.utils.validate_link?value=Biodox+3000+ppm+litro&options=Item&fetch=&_=1614980205185 HTTP/1.0" 200 -
22:46:15 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:15] "POST /api/method/erpnext.stock.get_item_details.get_item_details HTTP/1.0" 200 -
22:46:19 web.1 | *** *** *** *** BEFORE SAVE *** *** *** *** ***
22:46:20 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:20] "POST /api/method/frappe.desk.form.save.savedocs HTTP/1.0" 200 -
22:46:21 web.1 | 127.0.0.1 - - [05/Mar/2021 22:46:21] "GET /api/method/frappe.desk.notifications.get_open_count?doctype=Sales+Invoice&name=001-003-000000001&items=%5B%22Payment+Entry%22%2C%22Payment+Request%22%2C%22Journal+Entry%22%2C%22Invoice+Discounting%22%2C%22Dunning%22%2C%22Timesheet%22%2C%22Delivery+Note%22%2C%22Sales+Order%22%2C%22POS+Invoice%22%2C%22Sales+Invoice%22%2C%22Auto+Repeat%22%5D&_=1614980205186 HTTP/1.0" 200 -
: : : : : :
I would expect the logged print
statement to be :
22:46:19 web.1 | === === === === BEFORE SAVE === === === === ===
It should not be …
22:46:19 web.1 | *** *** *** *** BEFORE SAVE *** *** *** *** ***
… because the call to super()
is disabled.
I’ll be grateful for any hints as to how to get this to work
Questions
Is there a “please_dont_ignore_my_hooks()” command?
Notes
erpdev@loso:~/frappe-bench-DELS$ bench version
myApp 0.0.1
erpnext 13.0.0-beta.12
frappe 13.0.0-beta.11
erpdev@loso:~/frappe-bench-DELS$ lsb_release -a
Description: Ubuntu 20.04.2 LTS
Codename: focal
erpdev@loso:~/frappe-bench-DELS$ bench --site dev.erpnext.host clear-cache
erpdev@loso:~/frappe-bench-DELS$ bench --site dev.erpnext.host migrate
Migrating dev.erpnext.host
Updating DocTypes for frappe : [=============================] 100%
Updating DocTypes for erpnext : [============================] 100%
Updating DocTypes for myApp : [=============================] 100%
Updating Dashboard for frappe
Updating Dashboard for erpnext
Updating Dashboard for myApp
Updating customizations for Address
Updating customizations for Contact
Building search index for dev.erpnext.host
erpdev@loso:~/frappe-bench-DELS$