fix: incorrect batch fetched for the serialized items (#20119)

* fix: incorrect batch fetched for the serialized items

* Update stock_controller.py

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
rohitwaghchaure
2019-12-30 13:26:47 +05:30
committed by Nabin Hait
parent fe0adc8b25
commit 9af557f9d7
3 changed files with 35 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ class StockController(AccountsController):
def validate(self):
super(StockController, self).validate()
self.validate_inspection()
self.validate_serialized_batch()
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
if self.docstatus == 2:
@@ -42,6 +43,17 @@ class StockController(AccountsController):
gl_entries = self.get_asset_gl_entry(gl_entries)
make_gl_entries(gl_entries, from_repost=from_repost)
def validate_serialized_batch(self):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
for d in self.get("items"):
if hasattr(d, 'serial_no') and hasattr(d, 'batch_no') and d.serial_no and d.batch_no:
serial_nos = get_serial_nos(d.serial_no)
for serial_no_data in frappe.get_all("Serial No",
filters={"name": ("in", serial_nos)}, fields=["batch_no", "name"]):
if serial_no_data.batch_no != d.batch_no:
frappe.throw(_("Row #{0}: Serial No {1} does not belong to Batch {2}")
.format(d.idx, serial_no_data.name, d.batch_no))
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None):