Grayed out screen with no-interaction after adding row to items table


I’m using the following custom script to add a row to our table if the ordered amount makes the stock of an item go below 0. (We use a different item for items that need be delivered after a certain event)

frappe.ui.form.on("Sales Order Item", "qty", function(frm, doctype, name) {
         var row = locals[doctype][name];
         frappe.model.set_value(doctype, name, "projected_stock", row.actual_qty - row.qty);
         if(row.projected_stock < 0){
           var new_row_qty = (row.projected_stock*-1);
           row.qty = row.actual_qty;
           var new_row = cur_frm.add_child("items");
           new_row.item_code = row.item_code + " (order)";
           new_row.qty = new_row_qty;
           new_row.stock_uom = row.stock_uom;
           new_row.rate = row.rate;
           new_row.item_name = row.item_name;
           new_row.amount = new_row.qty * new_row.rate;
           new_row.supplier = row.supplier;

While I see the new row added with the correct information in the items table, the screen remains grayed out (as if the popup were still there), and there is no way to interact with any buttons or fields. What am I missing here?


Could you share or check the error in your Browser Console?

There is no error shown in my Chrome console. It feels like the popup screen isn’t properly closed?

This code immediately activates as soon as the focus is lost on the quantity field in the Sales Order Item popup when adding it to the table. So I don’t get to click “done” on the popup window as it seemingly closes. Is there a way to call a close on the popup window?

I have found a solution to the issue with the following code:

frappe.ui.form.on("Sales Order Item", "qty", function(frm, doctype, name) {
        var twin = window.self;
        <other code>


So in the beginning I call window.self to get the popup window and by the end I close it. Pretty straightforward, but I don’t know if this is hacky for the frappe framework?

This was not a real fix, it sometimes works, but sometimes doesn’t? Anybody have an idea?