Hi,
I am just starting out with the Frappe Framework in combination with ERPNext. As I understand, the advice is to never touch the original code, but rather use the hooks and “prefer extending over overriding”.
So I tried to use a hook in my custom app to set some initial System Settings:
The file is myapp/setup/install.py
:
import frappe
def after_install():
settings_doc = frappe.get_doc("System Settings")
setattr(settings_doc, "first_day_of_the_week", "Monday")
setattr(settings_doc, "float_precision", "2")
settings_doc.save()
frappe.db.commit()
and the line in the hooks.py
:
after_install = ["myapp.setup.install.after_install"]
Then I install the app using bench, and reload the site. The hook is definitely being executed because something changes, but not as I expect. The value for the “first day of the week” is lost, and the other one briefly shows “2” but as the site finishes loading it goes back to the old value “4”.
Here is a screenshot:
What is the reason for this? What am I doing wrong?
Thanks in advance!