So I know I can change it via the application itself after installation but how do I make it the default for every new installation? Is there a hook I can use for this in a custom app?
you can set the default values for a new installation of your custom app by using the defaults
attribute in your app’s __init__.py
file.
# my_custom_app/__init__.py
from frappe import _
app_name = "My Custom App"
app_title = _("My Custom App")
app_publisher = "My Company"
app_description = _("This is my custom app")
app_icon = "fa fa-cube"
app_color = "#3498db"
app_email = "support@mycompany.com"
app_version = "0.0.1"
defaults = [
{
"doctype": "Sales Order",
"fieldname": "my_custom_field",
"value": "My Default Value"
}
]
Hope this will help you out.
Thank you.
Thanks for responding! I was able to do this by using an after install script and setting a value in the db to 0
ie.
frappe.db.set_single_value("System Settings", "enable_onboarding", 0)
Here’s an example of how you could use the before_install
hook in your custom app to set the default value for enable_onboarding
to 0:
# my_custom_app/hooks.py
from frappe import db
def before_install():
db.set_single_value("System Settings", "enable_onboarding", 0)
In this code, we’re importing the db
module and defining a function called before_install
. Inside the function, we’re using db.set_single_value
to set the value of enable_onboarding
to 0 in the “System Settings” doctype.
Then, in your __init__.py
file, you can add the following code to specify the path to your hooks file:
# my_custom_app/__init__.py
from frappe import _
app_name = "My Custom App"
# ... app details here ...
# specify the path to your hooks file
app_hooks = {
"before_install": "my_custom_app.hooks.before_install"
}
defaults = [
{
"doctype": "Sales Order",
"fieldname": "my_custom_field",
"value": "My Default Value"
}
]
Hope this will help you out.
Thank you.