Stock Entry: Serial No Mandatory when purpose in Material Transfer, Sales Return, Purchase Return

This commit is contained in:
Anand Doshi 2014-06-25 13:31:02 +05:30
parent 610a405c85
commit a740f750c7
3 changed files with 18 additions and 2 deletions

View File

@ -424,8 +424,7 @@ class AccountsController(TransactionBase):
def get_stock_items(self):
stock_items = []
item_codes = list(set(item.item_code for item in
self.get(self.fname)))
item_codes = list(set(item.item_code for item in self.get(self.fname)))
if item_codes:
stock_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \

View File

@ -275,6 +275,16 @@ class StockController(AccountsController):
and voucher_no=%s""", (self.doctype, self.name)):
self.make_gl_entries()
def get_serialized_items(self):
serialized_items = []
item_codes = list(set([d.item_code for d in self.get(self.fname)]))
if item_codes:
serialized_items = frappe.db.sql_list("""select name from `tabItem`
where has_serial_no='Yes' and name in ({})""".format(", ".join(["%s"]*len(item_codes))),
tuple(item_codes))
return serialized_items
def update_gl_entries_after(posting_date, posting_time, warehouse_account=None, for_items=None):
def _delete_gl_entries(voucher_type, voucher_no):
frappe.db.sql("""delete from `tabGL Entry`

View File

@ -77,6 +77,7 @@ class StockEntry(StockController):
def validate_item(self):
stock_items = self.get_stock_items()
serialized_items = self.get_serialized_items()
for item in self.get("mtn_details"):
if item.item_code not in stock_items:
frappe.throw(_("{0} is not a stock Item").format(item.item_code))
@ -88,6 +89,12 @@ class StockEntry(StockController):
item.conversion_factor = 1
if not item.transfer_qty:
item.transfer_qty = item.qty * item.conversion_factor
if (self.purpose in ("Material Transfer", "Sales Return", "Purchase Return")
and not item.serial_no
and item.item_code in serialized_items):
frappe.throw(_("Row #{0}: Please specify Serial No for Item {1}").format(item.idx, item.item_code),
frappe.MandatoryError)
def validate_warehouse(self, pro_obj):
"""perform various (sometimes conditional) validations on warehouse"""