Wrong status view in listview with client script

Hello,
I have a light client script:

frappe.listview_settings['Purchase Order'] = {
	refresh: function(listview) {
	    listview.page.add_inner_button(("Disabled"), () => {
            window.location.href = "/app/item/?disabled=1";
	    });
	}
};

If the script is active then here are another statuses as usual:

Without script:
Screenshot from 2024-03-22 17-40-00

With script:

image

Is something wrong with my script, please?

Jiri Sir

1 Like

Hi @Jiri_Sir,

When you apply the listview client script then check the default purchase_order_list.js is applied or not. if applied then also get the script and set your script in the default script.

Please apply it.

frappe.listview_settings["Purchase Order"] = {
	add_fields: [
		"base_grand_total",
		"company",
		"currency",
		"supplier",
		"supplier_name",
		"per_received",
		"per_billed",
		"status",
	],
	get_indicator: function (doc) {
		if (doc.status === "Closed") {
			return [__("Closed"), "green", "status,=,Closed"];
		} else if (doc.status === "On Hold") {
			return [__("On Hold"), "orange", "status,=,On Hold"];
		} else if (doc.status === "Delivered") {
			return [__("Delivered"), "green", "status,=,Closed"];
		} else if (flt(doc.per_received, 2) < 100 && doc.status !== "Closed") {
			if (flt(doc.per_billed, 2) < 100) {
				return [
					__("To Receive and Bill"),
					"orange",
					"per_received,<,100|per_billed,<,100|status,!=,Closed",
				];
			} else {
				return [__("To Receive"), "orange", "per_received,<,100|per_billed,=,100|status,!=,Closed"];
			}
		} else if (
			flt(doc.per_received, 2) >= 100 &&
			flt(doc.per_billed, 2) < 100 &&
			doc.status !== "Closed"
		) {
			return [__("To Bill"), "orange", "per_received,=,100|per_billed,<,100|status,!=,Closed"];
		} else if (
			flt(doc.per_received, 2) >= 100 &&
			flt(doc.per_billed, 2) == 100 &&
			doc.status !== "Closed"
		) {
			return [__("Completed"), "green", "per_received,=,100|per_billed,=,100|status,!=,Closed"];
		}
	},
	onload: function (listview) {
		var method = "erpnext.buying.doctype.purchase_order.purchase_order.close_or_unclose_purchase_orders";

		listview.page.add_menu_item(__("Close"), function () {
			listview.call_for_selected_items(method, { status: "Closed" });
		});

		listview.page.add_menu_item(__("Reopen"), function () {
			listview.call_for_selected_items(method, { status: "Submitted" });
		});

		listview.page.add_action_item(__("Purchase Invoice"), () => {
			erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Invoice");
		});

		listview.page.add_action_item(__("Purchase Receipt"), () => {
			erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Receipt");
		});

		listview.page.add_action_item(__("Advance Payment"), () => {
			erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Payment Entry");
		});
	},
	refresh: function(listview) {
	    listview.page.add_inner_button(("Disabled"), () => {
            window.location.href = "/app/item/?disabled=1";
	    });
	}
};

Please check and set your scenario in script.

Output:

Reference:

Thank You!

Hello @NCP ,
thank you very much, it is working :wink:

What about “just” extending the original script? Is it possible, please?
This is overriding and I am afraid of I miss potential future changes in the core.
Thank you.

Jiri Sir

Hi @Jiri_Sir,

Provided script, you can also add in Client Script doctype. However, it’s essential to incorporate core code because if you don’t, the core functionality won’t function properly. So, if you wish to modify the code, you must include the core code and add your code based on the situation. You can also override the code in the custom app so please don’t add code in core.

Thank You!

Hello @NCP,
thank you very much for your answer.

Finally I have found this solution that “just” extends default (purchase_order_list.js) list_view settings:

let original_settings = frappe.listview_settings['Purchase Order'] || {};

let add_custom_buttons = {
    refresh: function (listview){
            listview.page.add_action_item(__("Custom Button"), () => {
		        //do the magic :-)
	    });
    }
};

$.extend( true, original_settings, add_custom_buttons);

Thank you.

Jiri Sir

1 Like