Issue while making child table read_only through script

Usecase: Don’t allow users to modify rate of items in “amended” purchase orders.
Version: v12.19.0 (version-12)

I’ve written below custom script for the usecase:

frappe.ui.form.on('Purchase Order',  {
    onload: function(frm) {
         if(cur_frm.doc.amended_from) {
            console.log(cur_frm.doc.amended_from);
            var df = frappe.meta.get_docfield("Purchase Order Item", "rate", cur_frm.doc.name);
    	    df.read_only = 1;
    	   cur_frm.refresh_field("items");
    	}
    }
});

This is not making the rate field read-only. However, if we add new item, the rate field is read-only for the new item.

Also, if I remove the if condition, rate field is read-only for all items.

Any idea how to fix it?