fix: UI freeze while selecting batched items in sales invoice
This commit is contained in:
@@ -417,7 +417,14 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
args: args,
|
args: args,
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message);
|
if (r.message.batch_no != null) {
|
||||||
|
frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message.batch_no);
|
||||||
|
} else if (r.message.msg_print) {
|
||||||
|
frappe.show_alert({
|
||||||
|
message: r.message.msg_print,
|
||||||
|
indicator:'orange'
|
||||||
|
}, 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -260,7 +260,9 @@ def set_batch_nos(doc, warehouse_field, throw=False, child_table="items"):
|
|||||||
warehouse = d.get(warehouse_field, None)
|
warehouse = d.get(warehouse_field, None)
|
||||||
if warehouse and qty > 0 and frappe.db.get_value("Item", d.item_code, "has_batch_no"):
|
if warehouse and qty > 0 and frappe.db.get_value("Item", d.item_code, "has_batch_no"):
|
||||||
if not d.batch_no:
|
if not d.batch_no:
|
||||||
d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no)
|
d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no).get(
|
||||||
|
"batch_no", None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse)
|
batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse)
|
||||||
if flt(batch_qty, d.precision("qty")) < flt(qty, d.precision("qty")):
|
if flt(batch_qty, d.precision("qty")) < flt(qty, d.precision("qty")):
|
||||||
@@ -282,6 +284,7 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
batch_no = None
|
batch_no = None
|
||||||
|
message = None
|
||||||
batches = get_batches(item_code, warehouse, qty, throw, serial_no)
|
batches = get_batches(item_code, warehouse, qty, throw, serial_no)
|
||||||
|
|
||||||
for batch in batches:
|
for batch in batches:
|
||||||
@@ -290,15 +293,18 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not batch_no:
|
if not batch_no:
|
||||||
frappe.msgprint(
|
message = _(
|
||||||
_(
|
"Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement"
|
||||||
"Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement"
|
).format(frappe.bold(item_code))
|
||||||
).format(frappe.bold(item_code))
|
|
||||||
)
|
|
||||||
if throw:
|
if throw:
|
||||||
|
frappe.msgprint(
|
||||||
|
_(
|
||||||
|
"Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement"
|
||||||
|
).format(frappe.bold(item_code))
|
||||||
|
)
|
||||||
raise UnableToSelectBatchError
|
raise UnableToSelectBatchError
|
||||||
|
|
||||||
return batch_no
|
return {"batch_no": batch_no, "msg_print": message}
|
||||||
|
|
||||||
|
|
||||||
def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
||||||
|
|||||||
@@ -1262,7 +1262,9 @@ class StockEntry(StockController):
|
|||||||
and ret.get("has_batch_no")
|
and ret.get("has_batch_no")
|
||||||
and not args.get("batch_no")
|
and not args.get("batch_no")
|
||||||
):
|
):
|
||||||
args.batch_no = get_batch_no(args["item_code"], args["s_warehouse"], args["qty"])
|
args.batch_no = get_batch_no(args["item_code"], args["s_warehouse"], args["qty"]).get(
|
||||||
|
"batch_no", None
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.purpose == "Send to Subcontractor" and self.get("purchase_order") and args.get("item_code")
|
self.purpose == "Send to Subcontractor" and self.get("purchase_order") and args.get("item_code")
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ def update_stock(args, out):
|
|||||||
):
|
):
|
||||||
|
|
||||||
if out.has_batch_no and not args.get("batch_no"):
|
if out.has_batch_no and not args.get("batch_no"):
|
||||||
out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty)
|
out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty).get("batch_no", None)
|
||||||
actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code)
|
actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code)
|
||||||
if actual_batch_qty:
|
if actual_batch_qty:
|
||||||
out.update(actual_batch_qty)
|
out.update(actual_batch_qty)
|
||||||
|
|||||||
Reference in New Issue
Block a user