Strange behaviour on Purchase Order (item) page

Hi There,

We have a custom field called Dept Code (Link to Cost Center) defined for Purchase Order Item doctype. See below screen shot for more detail on how the Dept Code and Project Name field are configured. When ever we change the value of 'Project Name" field for an Item, the value in Dept Code field disappears. Do you know why this is happening. It is quite annoying as users enters the value for Dept Code first and then chooses the Project Name but as soon as project name is choosen the value in Dept Code field disappears. Is there any relationship between Cost Center and Project Name doc types which is causing this?


Do you have any custom script related to this?

Yes. See below.

// when we initially implemented ERPNext, we had imported some old PO which had UNKNOWN Dept code and Cost
// center. But we don’t want user to use it for new PO. So below script is for that.

frappe.ui.form.on("Purchase Order", "validate", function(frm) {
     for (var i in cur_frm.doc.items){
          if ((cur_frm.doc.items[i].expense_account.indexOf('UNKNOWN') !== -1) || (frm.doc.items[i].cost_center.indexOf('UNKNOWN') !== -1)) {
          validated = false;
          msgprint('ERROR: <b>UNKNOWN Department Code or Expense Code is not allowed.</b> <P> Please correct it and save again');
           }
       }

});

// To restrict expense account to selected company. This should be part of the core product.
frappe.ui.form.on("Purchase Order", "onload", function(frm) {
    cur_frm.set_query("expense_account","items", function() {
        return {
            "filters": {
                "company": cur_frm.doc.company
            }
        };
    });
});

// to restrict cost center selection to selected company. This should be part of the core product.
frappe.ui.form.on("Purchase Order", "onload", function(frm) {
    cur_frm.set_query("cost_center","items", function() {
        return {
            "filters": {
                "company": cur_frm.doc.company
            }
        };
    });
});

Seems like a strange behavior. Could be due to multiple ajax queries being run simultaneously, though I can’t figure where.

@rmehta

I have removed all the custom script from the Purchase Order doctype. There is no custom script but the issue still exists. So it seems like a bug. Do you want to check this at your end before I create a bug/issue?

Mayur

@mayur_hotmail can you try and debug this a bit more. Check the order in which the requests are executed via your console.

There are some old style ajax scripts that can override the fetch links, but that would take some time to debug and analyze. I am not sure how we can take this up immediately though.