From b9314da0544a941a06a55f6dc0b390b7b1637825 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 24 Dec 2012 18:38:32 +0530 Subject: [PATCH] validate is stock item in stock entry --- stock/doctype/stock_entry/stock_entry.js | 2 ++ stock/doctype/stock_entry/stock_entry.py | 1 - .../stock_ledger_entry/stock_ledger_entry.py | 26 ++++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index 724b215d3f..a6d233e258 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -160,6 +160,7 @@ fld.get_query = function(doc, cdt, cdn) { return 'SELECT tabItem.name, tabItem.description, tabBin.actual_qty ' + 'FROM tabItem, tabBin ' + 'WHERE tabItem.name = tabBin.item_code ' + + 'AND tabItem.is_stock_item = "Yes"' + 'AND ifnull(`tabBin`.`actual_qty`,0) > 0 ' + 'AND tabBin.warehouse="'+ d.s_warehouse +'" ' + 'AND tabItem.docstatus < 2 ' @@ -171,6 +172,7 @@ fld.get_query = function(doc, cdt, cdn) { return 'SELECT tabItem.name, tabItem.description ' + 'FROM tabItem ' + 'WHERE tabItem.docstatus < 2 ' + + 'AND tabItem.is_stock_item = "Yes"' + 'AND (ifnull(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` > NOW() OR `tabItem`.`end_of_life`="0000-00-00") ' + 'AND tabItem.%(key)s LIKE "%s" ' + 'ORDER BY tabItem.name ASC ' diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index dae2d10ab6..deb1bd35d4 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -36,7 +36,6 @@ class DocType(TransactionBase): def validate(self): self.validate_serial_nos() - pro_obj = self.doc.production_order and \ get_obj('Production Order', self.doc.production_order) or None diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 0994e505c0..fae2fcb9f6 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -28,6 +28,14 @@ class DocType: def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist + + def validate(self): + self.validate_mandatory() + self.validate_posting_time() + self.validate_item() + self.actual_amt_check() + self.check_stock_frozen_date() + self.scrub_posting_time() #check for item quantity available in stock def actual_amt_check(self): @@ -53,13 +61,19 @@ class DocType: msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1) def validate_item(self): - item_det = sql("select name, has_batch_no, docstatus from tabItem where name = '%s'" % self.doc.item_code) + item_det = sql("""select name, has_batch_no, docstatus, + ifnull(is_stock_item, 'No') from tabItem where name=%s""", + self.doc.item_code) # check item exists if item_det: item_det = item_det and item_det[0] else: msgprint("Item: '%s' does not exist in the system. Please check." % self.doc.item_code, raise_exception = 1) + + if item_det[3]!='Yes': + webnotes.msgprint("""Item: "%s" is not a Stock Item.""" % self.doc.item_code, + raise_exception=1) # check if item is trashed if cint(item_det[2])==2: @@ -96,12 +110,4 @@ class DocType: self.doc.posting_time = '00:00' if len(self.doc.posting_time.split(':')) > 2: self.doc.posting_time = '00:00' - - - def validate(self): - self.validate_mandatory() - self.validate_posting_time() - self.validate_item() - self.actual_amt_check() - self.check_stock_frozen_date() - self.scrub_posting_time() + \ No newline at end of file