Frappe Cloud Support Partners Foundation Frappe School

Override the original source code functions

I have created custom scripts and server scripts to modify the existing method in Python of the original ERPNext. I realised that for the same event, the original codes will run after the custom script’s codes. Is there a way to only run the event on custom script?

1 Like

what is the code ?

I want to change the formula to calculate the fg_completed_quantity.

Here is my code for custom script in ERPNext.

frappe.ui.form.on('Stock Entry', {
work_order: function(frm) {
	if(!frm.doc.work_order || frm.doc.job_card) {
    var fg_completed_qty;
		method: "get_work_order_details2",
		args: {
			work_order: frm.doc.work_order,
		callback: function(r) {
			if (!r.exc) {
				$.each(["from_bom", "bom_no", "fg_completed_qty", "use_multi_level_bom"], function(i, field) {
					frm.set_value(field, r.message[field]);
		        fg_completed_qty = r.message.fg_completed_qty;
				if (frm.doc.purpose == "Material Transfer for Manufacture" && !frm.doc.to_warehouse)
					frm.set_value("to_warehouse", r.message.wip_warehouse);

				if (frm.doc.purpose == "Manufacture" || frm.doc.purpose == "Material Consumption for Manufacture" ) {
					if (frm.doc.purpose == "Manufacture") {
						if (!frm.doc.to_warehouse) frm.set_value("to_warehouse", r.message.fg_warehouse);
					if (!frm.doc.from_warehouse) frm.set_value("from_warehouse", r.message.wip_warehouse);

To override methods, you can use hooks in a custom app. See here:

okay , what is the event ? and why are you creating an script type api ?

My initial thought was to override the frappe whitelisted python method and found out that the API server script can be called by

1 Like

Hey, did you find out the way to implement hook?

Thank you!