Custom Controllers

Check out my answer here - Calendar view for sales opportunity? - #6 by alec_ruizramon1
Same idea as that, be sure to run bench build and bench clear-cache to get the js files built and included!

You’ll also want to put the put your js function inside something that only binds it to the PO - something like this should work …
frappe.ui.form.on(“Purchase Order”, “refresh”, function() {
// code
}