diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 9b8ccac90ed..368a3ff8390 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -383,15 +383,17 @@ class StatusUpdater(Document): def fetch_items_with_pending_qty(self, args, item_field, items): doctype = frappe.qb.DocType(args["target_dt"]) - item_field = doctype[item_field] + item_field_col = doctype[item_field] target_ref_field = doctype[args["target_ref_field"]] target_field = doctype[args["target_field"]] - return ( + is_qty_check = "qty" in args["target_ref_field"] + + query = ( frappe.qb.from_(doctype) .select( doctype.name, - item_field.as_("item_code"), + item_field_col.as_("item_code"), target_ref_field, target_field, doctype.parenttype, @@ -400,9 +402,18 @@ class StatusUpdater(Document): .where(target_ref_field < target_field) .where(doctype.name.isin(items)) .where(doctype.docstatus == 1) - .run(as_dict=True) ) + if is_qty_check: + item_table = frappe.qb.DocType("Item") + query = ( + query.join(item_table) + .on(item_table.name == item_field_col) + .where(item_table.is_stock_item == 1) + ) + + return query.run(as_dict=True) + def check_overflow_with_allowance(self, item, args): """ Checks if there is overflow considering a relaxation allowance.