[fix] [minor] item validation

This commit is contained in:
Nabin Hait 2013-12-17 17:45:50 +05:30
parent 592d27e7f1
commit a4080eb840

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, flt, cint from webnotes.utils import cstr, flt
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes import msgprint, _ from webnotes import msgprint, _
@ -116,40 +116,29 @@ class DocType(DocListController, WebsiteGenerator):
self.doc.is_pro_applicable = "No" self.doc.is_pro_applicable = "No"
if self.doc.is_pro_applicable == 'Yes' and self.doc.is_stock_item == 'No': if self.doc.is_pro_applicable == 'Yes' and self.doc.is_stock_item == 'No':
msgprint("As Production Order can be made for this Item, then Is Stock Item Should be 'Yes' as we maintain it's stock. Refer Manufacturing and Inventory section.", raise_exception=1) webnotes.throw(_("As Production Order can be made for this item, \
it must be a stock item."))
if self.doc.has_serial_no == 'Yes' and self.doc.is_stock_item == 'No': if self.doc.has_serial_no == 'Yes' and self.doc.is_stock_item == 'No':
msgprint("'Has Serial No' can not be 'Yes' for non-stock item", raise_exception=1) msgprint("'Has Serial No' can not be 'Yes' for non-stock item", raise_exception=1)
def check_for_active_boms(self): def check_for_active_boms(self):
def _check_for_active_boms(field_label): if self.doc.is_active != "Yes" or self.doc.is_purchase_item != "Yes":
if field_label in ['Is Active', 'Is Purchase Item']: bom_mat = webnotes.conn.sql("""select distinct t1.parent
bom_mat = webnotes.conn.sql("""select distinct t1.parent from `tabBOM Item` t1, `tabBOM` t2 where t2.name = t1.parent
from `tabBOM Item` t1, `tabBOM` t2 where t2.name = t1.parent and t1.item_code =%s and ifnull(t1.bom_no, '') = '' and t2.is_active = 1
and t1.item_code =%s and ifnull(t1.bom_no, '') = '' and t2.is_active = 1 and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
if bom_mat and bom_mat[0][0]: if bom_mat and bom_mat[0][0]:
msgprint(_(field_label) + _(" should be 'Yes'. As Item: ") + self.doc.name + webnotes.throw(_("Item must be active and purchase item, \
_(" is present in one or many Active BOMs"), raise_exception=1) as it is present in one or many Active BOMs"))
if ((field_label == 'Allow Production Order' if self.doc.is_manufactured_item != "Yes":
and self.doc.is_sub_contracted_item != 'Yes') bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s
or (field_label == 'Is Sub Contracted Item' and is_active = 1""", (self.doc.name,))
and self.doc.is_manufactured_item != 'Yes')): if bom and bom[0][0]:
bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s webnotes.throw(_("""Allow Bill of Materials should be 'Yes'. Because one or many \
and is_active = 1""", (self.doc.name,)) active BOMs present for this item"""))
if bom and bom[0][0]:
msgprint(_(field_label) + _(" should be 'Yes'. As Item: ") + self.doc.name +
_(" is present in one or many Active BOMs"), raise_exception=1)
if not cint(self.doc.fields.get("__islocal")):
fl = {'is_manufactured_item' :'Allow Bill of Materials',
'is_sub_contracted_item':'Is Sub Contracted Item',
'is_purchase_item' :'Is Purchase Item',
'is_pro_applicable' :'Allow Production Order'}
for d in fl:
if cstr(self.doc.fields.get(d)) != 'Yes':
_check_for_active_boms(fl[d])
def fill_customer_code(self): def fill_customer_code(self):
""" Append all the customer codes and insert into "customer_code" field of item table """ """ Append all the customer codes and insert into "customer_code" field of item table """