Customization Best Practice: Fixtures vs Internal JS of a doctype

As we know in frappe/ERPNext, there’s internal js file inside doctype folder and also js files under fixtures folder and both can be used to customize the client side behavior.

I still wonder until now: what’s the difference between those files? when to use the the fixtures one and the internal js for a doctype.

I need a proper answer please, some examples will be appreciated

I just did a search in ERPNext repo. I don’t see any folders named “fixtures” can you send an example doctype that has js files in both folders?

Sorry, neither inside frappe folder nor ERPNext folder. I mean inside an ERPNext custom app.

Standard JS file:

This file is created when new doctype is created. If you are the creator of the app and doctype, use this js file directly.

Fixtures :

Any DocType can be exported as fixtures. Need to specify doctype and filters in of custom app.
bench export-fixtures command is used to export the fixtures. Make sure you filter fixtures before exporting or it will export all fixtures from all apps causing conflicts.
Custom Script is not recommended to be exported as fixture if you already have a custom app.

Best way to extend current js script with custom app is to use doctype_js hook.



So if you need custom script for Standard Doctype, lets say Quotation, you should edit this file


like this?

doctype_js = {
	"Address": "public/js/address.js",
	"Communication": "public/js/communication.js",
	"Event": "public/js/event.js",
	"Newsletter": "public/js/newsletter.js"
    "Quotation": "path-to-js-file-in-my-app"

And where to put that custom file in my apps folder structure?

Refer the official erpnext_shipping app.

Keep the file in public/js directory in custom app

You are right, it works the same way also for Standard Doctypes, thanks!
I added
doctype_js = {"Quotation" : "public/js/Quotation.js"}
to apps/custom_app/custom_app/ and custom script code to apps/custom_app/custom_app/public/js/Quotation.js, removed script from the fixtures and reinstalled app.

I have one more question - is exporting Standard Doctype as a fixture good practice/update-proof?
If I have to make change to Standard Doctype (ie change naming for Project to series, which cannot be done in customize form), I found the only way to put this change to the custom app via exporting whole Doctype as a fixture. Is it safe from the point of future updates to new versions?

You should start new topic for new questions. Easier for users to search later.

python script that runs after install can be used?

refer erpnext code for after_install hook:

I thought I was asking about topic regarding customization best practices, but sorry for that. I copied it to new topic, could you please response there? Thanks a lot!