Skip to content

Commit

Permalink
Merge pull request #35562 from rohitwaghchaure/fixed-validation-for-s…
Browse files Browse the repository at this point in the history
…tock-entry

fix: added validation for insufficient stock during stock transfer
  • Loading branch information
rohitwaghchaure authored Jun 5, 2023
2 parents b1ef19a + dcb0462 commit 9e650a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
36 changes: 20 additions & 16 deletions erpnext/public/js/utils/serial_no_batch_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
}
});

if (this.frm.doc.doctype === 'Stock Entry'
&& this.frm.doc.purpose === 'Manufacture') {
fields.push({
fieldtype: 'Column Break',
});

fields.push({
fieldtype: 'Link',
fieldname: 'work_order',
label: __('For Work Order'),
options: 'Work Order',
read_only: 1,
default: this.frm.doc.work_order,
});

fields.push({
fieldtype: 'Section Break',
});
}

fields.push({
fieldtype: 'Column Break',
});
Expand Down Expand Up @@ -101,22 +121,6 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
});
}

if (this.frm.doc.doctype === 'Stock Entry'
&& this.frm.doc.purpose === 'Manufacture') {
fields.push({
fieldtype: 'Column Break',
});

fields.push({
fieldtype: 'Link',
fieldname: 'work_order',
label: __('For Work Order'),
options: 'Work Order',
read_only: 1,
default: this.frm.doc.work_order,
});
}

if (this.item?.outward) {
fields = [...this.get_filter_fields(), ...fields];
} else {
Expand Down
6 changes: 5 additions & 1 deletion erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,11 @@ def set_serial_no_batch_for_finished_good(self):
return

for d in self.items:
if d.is_finished_item and d.item_code == self.pro_doc.production_item:
if (
d.is_finished_item
and d.item_code == self.pro_doc.production_item
and not d.serial_and_batch_bundle
):
serial_nos = self.get_available_serial_nos()
if serial_nos:
row = frappe._dict({"serial_nos": serial_nos[0 : cint(d.qty)]})
Expand Down
12 changes: 12 additions & 0 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ def make_serial_and_batch_bundle(self):
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
Expand Down Expand Up @@ -767,6 +768,17 @@ def update_serial_and_batch_entries(self):
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
Expand Down

0 comments on commit 9e650a0

Please sign in to comment.