Want to override, extend a js file

In Purchase Order Doctype js file, i want to add a button “Action” with Dropdown say “A” & “B”, since directly changing the core files is bad practice, i want to do it through Hooks

i did below steps but failed

  1. created a file “purchase_order_custom.js”, and stored in custom_app–>public–>js–>purchase_order_custom.js (see below image to exactly find where i created the file)
    image

  2. in the file tried two codes just to see does this code even get hit or not (not added exact functionality b/z first i wanted to see does this work or not)

a)

frappe.ui.form.on('Purchase Order', {
    supplier: function(frm) {
        frappe.msgprint("Supplier has been selected!");
    }
});

b)

class CustomPurchaseOrder extends frappe.ui.form.PurchaseOrder {
      supplier(){
        frappe.msgprint("HHHHHHHHHHHHHHHHHHHHhh");
    }
}

frappe.ui.form.PurchaseOrder = CustomPurchaseOrder;
  1. added this in Hooks.py of custom app
    app_include_js = “/assets/embee/public/js/purchase_order_custom.js”

please anyone help, i am stuck in this problem from a long time
can’t find an exact solution in similar question asked on forum

Hello,

You should add this under the doctype_js of the hooks file.

Like this:

@Maheshwari_Bhavesh Okay, you mean i simply copy whole code of purchase_order.py file
and add my functionality as i need to change

added this as you said
doctype_js = {“Purchase Order” : “public/js/purchase_order_custom.js”}

It Works, but i want to ask one question

  1. will it increase load if i copy whole js code of this “Purchase Order” doctype
  2. also how this calling works now, i mean when the earlier purchase_order.js was called now it will be called “purchase_order_custom.js”

Hi @Rajat96318:

Just curiosity … why not use a simple client script for that?
Sometimes we choose the hardest way :wink: Probably itsn’t your case, but …

1 Like