[fix] [minor] item validation
This commit is contained in:
parent
592d27e7f1
commit
a4080eb840
@ -4,7 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import cstr, flt, cint
|
||||
from webnotes.utils import cstr, flt
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes.model.bean import getlist
|
||||
from webnotes import msgprint, _
|
||||
@ -116,40 +116,29 @@ class DocType(DocListController, WebsiteGenerator):
|
||||
self.doc.is_pro_applicable = "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':
|
||||
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(field_label):
|
||||
if field_label in ['Is Active', 'Is Purchase Item']:
|
||||
bom_mat = webnotes.conn.sql("""select distinct 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 t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
|
||||
if bom_mat and bom_mat[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 ((field_label == 'Allow Production Order'
|
||||
and self.doc.is_sub_contracted_item != 'Yes')
|
||||
or (field_label == 'Is Sub Contracted Item'
|
||||
and self.doc.is_manufactured_item != 'Yes')):
|
||||
bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s
|
||||
and is_active = 1""", (self.doc.name,))
|
||||
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])
|
||||
if self.doc.is_active != "Yes" or self.doc.is_purchase_item != "Yes":
|
||||
bom_mat = webnotes.conn.sql("""select distinct 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 t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
|
||||
|
||||
if bom_mat and bom_mat[0][0]:
|
||||
webnotes.throw(_("Item must be active and purchase item, \
|
||||
as it is present in one or many Active BOMs"))
|
||||
|
||||
if self.doc.is_manufactured_item != "Yes":
|
||||
bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s
|
||||
and is_active = 1""", (self.doc.name,))
|
||||
if bom and bom[0][0]:
|
||||
webnotes.throw(_("""Allow Bill of Materials should be 'Yes'. Because one or many \
|
||||
active BOMs present for this item"""))
|
||||
|
||||
def fill_customer_code(self):
|
||||
""" Append all the customer codes and insert into "customer_code" field of item table """
|
||||
|
Loading…
Reference in New Issue
Block a user