Merge pull request #2628 from neilLasrado/batch-validation
Batch Validation
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 3f9e03b..c212811 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -64,7 +64,6 @@
self.validate_valuation_rate()
self.set_total_amount()
-
def on_submit(self):
self.update_stock_ledger()
@@ -330,7 +329,8 @@
"""validation: finished good quantity should be same as manufacturing quantity"""
for d in self.get('items'):
if d.bom_no and flt(d.transfer_qty) != flt(self.fg_completed_qty):
- frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}").format(d.idx, d.transfer_qty, self.fg_completed_qty))
+ frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \
+ format(d.idx, d.transfer_qty, self.fg_completed_qty))
def validate_return_reference_doc(self):
"""validate item with reference doc"""
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 7b65a67..c5c28d8 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -62,15 +62,16 @@
frappe.throw(_("Item {0} must be a stock Item").format(self.item_code))
# check if batch number is required
- if item_det.has_batch_no =='Yes' and self.voucher_type != 'Stock Reconciliation':
- if not self.batch_no:
- frappe.throw("Batch number is mandatory for Item {0}".format(self.item_code))
-
- # check if batch belongs to item
- if not frappe.db.get_value("Batch",
- {"item": self.item_code, "name": self.batch_no}):
- frappe.throw(_("{0} is not a valid Batch Number for Item {1}").format(self.batch_no, self.item_code))
-
+ if self.voucher_type != 'Stock Reconciliation':
+ if item_det.has_batch_no =='Yes':
+ if not self.batch_no:
+ frappe.throw(_("Batch number is mandatory for Item {0}").format(self.item_code))
+ elif not frappe.db.get_value("Batch",{"item": self.item_code, "name": self.batch_no}):
+ frappe.throw(_("{0} is not a valid Batch Number for Item {1}").format(self.batch_no, self.item_code))
+
+ elif item_det.has_batch_no =='No' and self.batch_no:
+ frappe.throw(_("The Item {0} cannot have Batch").format(self.item_code))
+
if item_det.has_variants:
frappe.throw(_("Stock cannot exist for Item {0} since has variants").format(self.item_code),
ItemTemplateCannotHaveStock)