I believe there are still many users in the community like myself which have yet to fully understand this new feature, Server Script. Your guidance would be greatly appreciated. Thank you in advance.
I’ll answer the best I can:
Technically yes, everything is possible.
That being said, you’ll have a major issue when you will update/upgrade your frappe/erpnext version. You might loose every changes you made because all of those changes will be in frappe/erpnext folders. You could always merge your changes with theirs, but I don’t garentee it will work as you expected.
You could also write a custom script (js only) in ‘Custom Script’ Doctype. This code is in the DB instead of frappe/erpnext directory. The downside of this option, is that if something happen to your server (ex: bench migrate), you’ll loose that custom script. Which is quite a big downside honestly. To keep it, you need to add it to public/yourapp.js or add it in hook.py as a fixtures.
Is there a reason why you don’t want to create a custom app?
With a custom app, you’ll gain so much more freedom regarding those kind of changes.
I think that you can use the “API” form of the doctype “Server Script” to create the python whitelisted method. And the “Custom Script” doctype to create the JS part. They are not going to be deleted on a migrate. They work like every doctype, for example, the customers are not deleted in a migrate. You are going to lose it if you do a bench reinstall for example.
I’m trying this (putting the python code / query in the Server Script doctype of type API) but encountering the error AttributeError: module has no attribute 'whitelist' when I try to call the API method. I’ve added @frappe.whitelist() in the Server script.