fix: added validation for insufficient stock during stock transfer

This commit is contained in:
Rohit Waghchaure
2023-06-05 16:56:29 +05:30
parent b1ef19a0cd
commit dcb0462d51
3 changed files with 37 additions and 17 deletions

View File

@@ -738,6 +738,7 @@ class SerialBatchCreation:
return frappe._dict({})
doc.save()
self.validate_qty(doc)
if not hasattr(self, "do_not_submit") or not self.do_not_submit:
doc.flags.ignore_voucher_validation = True
@@ -767,6 +768,17 @@ class SerialBatchCreation:
doc.save()
return doc
def validate_qty(self, doc):
if doc.type_of_transaction == "Outward":
precision = doc.precision("total_qty")
total_qty = abs(flt(doc.total_qty, precision))
required_qty = abs(flt(self.actual_qty, precision))
if required_qty - total_qty > 0:
msg = f"For the item {bold(doc.item_code)}, the Avaliable qty {bold(total_qty)} is less than the Required Qty {bold(required_qty)} in the warehouse {bold(doc.warehouse)}. Please add sufficient qty in the warehouse."
frappe.throw(msg, title=_("Insufficient Stock"))
def set_auto_serial_batch_entries_for_outward(self):
from erpnext.stock.doctype.batch.batch import get_available_batches
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos_for_outward