def validate_item_fetch(args, item): from stock.utils import validate_end_of_life validate_end_of_life(item.name, item.end_of_life) # validate company if not args.company: msgprint(_("Please specify Company"), raise_exception=True)
def validate_item(self, item_code, row_num): from stock.utils import validate_end_of_life, validate_is_stock_item, \ validate_cancelled_item # using try except to catch all validation msgs and display together try: item = webnotes.doc("Item", item_code) # end of life and stock item validate_end_of_life(item_code, item.end_of_life, verbose=0) validate_is_stock_item(item_code, item.is_stock_item, verbose=0) # item should not be serialized if item.has_serial_no == "Yes": raise webnotes.ValidationError, (_("Serialized Item: '") + item_code + _("""' can not be managed using Stock Reconciliation.\ You can add/delete Serial No directly, \ to modify stock of this item.""")) # docstatus should be < 2 validate_cancelled_item(item_code, item.docstatus, verbose=0) except Exception, e: self.validation_messages.append(_("Row # ") + ("%d: " % (row_num+2)) + cstr(e))
def validate_item(self, item_code, row_num): from stock.utils import validate_end_of_life, validate_is_stock_item, \ validate_cancelled_item # using try except to catch all validation msgs and display together try: item = webnotes.doc("Item", item_code) if not item: raise webnotes.ValidationError, (_("Item: {0} not found in the system").format(item_code)) # end of life and stock item validate_end_of_life(item_code, item.end_of_life, verbose=0) validate_is_stock_item(item_code, item.is_stock_item, verbose=0) # item should not be serialized if item.has_serial_no == "Yes": raise webnotes.ValidationError, (_("Serialized item: {0} can not be managed \ using Stock Reconciliation, use Stock Entry instead").format(item_code)) # item managed batch-wise not allowed if item.has_batch_no == "Yes": raise webnotes.ValidationError, (_("Item: {0} managed batch-wise, can not be \ reconciled using Stock Reconciliation, instead use Stock Entry").format(item_code)) # docstatus should be < 2 validate_cancelled_item(item_code, item.docstatus, verbose=0) except Exception, e: self.validation_messages.append(_("Row # ") + ("%d: " % (row_num)) + cstr(e))
def validate_for_items(self, obj): check_list, chk_dupl_itm=[],[] for d in getlist( obj.doclist, obj.fname): # validation for valid qty if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): webnotes.throw("Please enter valid qty for item %s" % cstr(d.item_code)) # udpate with latest quantities bin = webnotes.conn.sql("""select projected_qty from `tabBin` where item_code = %s and warehouse = %s""", (d.item_code, d.warehouse), as_dict=1) f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0} if d.doctype == 'Purchase Receipt Item': f_lst.pop('received_qty') for x in f_lst : if d.fields.has_key(x): d.fields[x] = f_lst[x] item = webnotes.conn.sql("""select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from `tabItem` where name=%s""", d.item_code) if not item: webnotes.throw("Item %s does not exist in Item Master." % cstr(d.item_code)) from stock.utils import validate_end_of_life validate_end_of_life(d.item_code, item[0][3]) # validate stock item if item[0][0]=='Yes' and d.qty and not d.warehouse: webnotes.throw("Warehouse is mandatory for %s, since it is a stock item" % d.item_code) # validate purchase item if item[0][1] != 'Yes' and item[0][2] != 'Yes': webnotes.throw("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code)) # list criteria that should not repeat if item is stock item e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or d.fields.has_key('sales_order_no') and d.sales_order_no or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or ''] # if is not stock item f = [d.schedule_date, d.item_code, d.description] ch = webnotes.conn.sql("""select is_stock_item from `tabItem` where name = %s""", d.item_code) if ch and ch[0][0] == 'Yes': # check for same items if e in check_list: webnotes.throw("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n Please change any of the field value to enter the item twice""" % d.item_code) else: check_list.append(e) elif ch and ch[0][0] == 'No': # check for same items if f in chk_dupl_itm: webnotes.throw("""Item %s has been entered more than once with same description, schedule date.\n Please change any of the field value to enter the item twice.""" % d.item_code) else: chk_dupl_itm.append(f)
def validate_item(self, item_code, row_num): from stock.utils import validate_end_of_life, validate_is_stock_item, \ validate_cancelled_item # using try except to catch all validation msgs and display together try: item = webnotes.doc("Item", item_code) if not item: raise webnotes.ValidationError, ( _("Item: {0} not found in the system").format(item_code)) # end of life and stock item validate_end_of_life(item_code, item.end_of_life, verbose=0) validate_is_stock_item(item_code, item.is_stock_item, verbose=0) # item should not be serialized if item.has_serial_no == "Yes": raise webnotes.ValidationError, ( _("Serialized item: {0} can not be managed \ using Stock Reconciliation, use Stock Entry instead").format(item_code)) # item managed batch-wise not allowed if item.has_batch_no == "Yes": raise webnotes.ValidationError, ( _("Item: {0} managed batch-wise, can not be \ reconciled using Stock Reconciliation, instead use Stock Entry").format( item_code)) # docstatus should be < 2 validate_cancelled_item(item_code, item.docstatus, verbose=0) except Exception, e: self.validation_messages.append( _("Row # ") + ("%d: " % (row_num)) + cstr(e))
def validate_for_items(self, obj): check_list, chk_dupl_itm=[],[] for d in getlist( obj.doclist, obj.fname): # validation for valid qty if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): msgprint("Please enter valid qty for item %s" % cstr(d.item_code)) raise Exception # udpate with latest quantities bin = webnotes.conn.sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0} if d.doctype == 'Purchase Receipt Item': f_lst.pop('received_qty') for x in f_lst : if d.fields.has_key(x): d.fields[x] = f_lst[x] item = webnotes.conn.sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s", d.item_code) if not item: msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True) from stock.utils import validate_end_of_life validate_end_of_life(d.item_code, item[0][3]) # validate stock item if item[0][0]=='Yes' and d.qty and not d.warehouse: msgprint("Warehouse is mandatory for %s, since it is a stock item" % d.item_code, raise_exception=1) # validate purchase item if item[0][1] != 'Yes' and item[0][2] != 'Yes': msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True) # list criteria that should not repeat if item is stock item e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or ''] # if is not stock item f = [d.schedule_date, d.item_code, d.description] ch = webnotes.conn.sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code) if ch and ch[0][0] == 'Yes': # check for same items if e in check_list: msgprint("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n Please change any of the field value to enter the item twice""" % d.item_code, raise_exception = 1) else: check_list.append(e) elif ch and ch[0][0] == 'No': # check for same items if f in chk_dupl_itm: msgprint("""Item %s has been entered more than once with same description, schedule date.\n Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1) else: chk_dupl_itm.append(f)
def get_item_details(args): """ args = { "doctype": "", "docname": "", "item_code": "", "warehouse": None, "supplier": None, "transaction_date": None, "conversion_rate": 1.0 } """ if isinstance(args, basestring): args = json.loads(args) args = webnotes._dict(args) item_wrapper = webnotes.bean("Item", args.item_code) item = item_wrapper.doc from stock.utils import validate_end_of_life validate_end_of_life(item.name, item.end_of_life) # fetch basic values out = webnotes._dict() out.update({ "item_name": item.item_name, "item_group": item.item_group, "brand": item.brand, "description": item.description, "qty": 0, "stock_uom": item.stock_uom, "uom": item.stock_uom, "conversion_factor": 1.0, "warehouse": args.warehouse or item.default_warehouse, "item_tax_rate": json.dumps( dict( ([d.tax_type, d.tax_rate] for d in item_wrapper.doclist.get({"parentfield": "item_tax"}) ))), "batch_no": None, "expense_head": item.purchase_account, "cost_center": item.cost_center }) if args.supplier: item_supplier = item_wrapper.doclist.get({ "parentfield": "item_supplier_details", "supplier": args.supplier }) if item_supplier: out["supplier_part_no"] = item_supplier[0].supplier_part_no if out.warehouse: out.projected_qty = webnotes.conn.get_value("Bin", { "item_code": item.name, "warehouse": out.warehouse }, "projected_qty") if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days( args.transaction_date, item.lead_time_days) # set zero out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \ out.import_ref_rate = out.import_rate = 0.0 if args.doctype in [ "Purchase Order", "Purchase Invoice", "Purchase Receipt", "Supplier Quotation" ]: # try fetching from price list if args.price_list_name and args.price_list_currency: rates_as_per_price_list = get_rates_as_per_price_list( args, item_wrapper.doclist) if rates_as_per_price_list: out.update(rates_as_per_price_list) # if not found, fetch from last purchase transaction if not out.purchase_rate: last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate) if last_purchase: out.update(last_purchase) return out
def get_item_details(args): """ args = { "doctype": "", "docname": "", "item_code": "", "warehouse": None, "supplier": None, "transaction_date": None, "conversion_rate": 1.0 } """ if isinstance(args, basestring): args = json.loads(args) args = webnotes._dict(args) item_wrapper = webnotes.bean("Item", args.item_code) item = item_wrapper.doc from stock.utils import validate_end_of_life validate_end_of_life(item.name, item.end_of_life) # fetch basic values out = webnotes._dict() out.update({ "item_name": item.item_name, "item_group": item.item_group, "brand": item.brand, "description": item.description, "qty": 0, "stock_uom": item.stock_uom, "uom": item.stock_uom, "conversion_factor": 1.0, "warehouse": args.warehouse or item.default_warehouse, "item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in item_wrapper.doclist.get({"parentfield": "item_tax"})))), "batch_no": None, "expense_head": item.purchase_account, "cost_center": item.cost_center }) if args.supplier: item_supplier = item_wrapper.doclist.get({"parentfield": "item_supplier_details", "supplier": args.supplier}) if item_supplier: out["supplier_part_no"] = item_supplier[0].supplier_part_no if out.warehouse: out.projected_qty = webnotes.conn.get_value("Bin", {"item_code": item.name, "warehouse": out.warehouse}, "projected_qty") if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, item.lead_time_days) # set zero out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \ out.import_ref_rate = out.import_rate = 0.0 if args.doctype in ["Purchase Order", "Purchase Invoice", "Purchase Receipt", "Supplier Quotation"]: # try fetching from price list if args.price_list_name and args.price_list_currency: rates_as_per_price_list = get_rates_as_per_price_list(args, item_wrapper.doclist) if rates_as_per_price_list: out.update(rates_as_per_price_list) # if not found, fetch from last purchase transaction if not out.purchase_rate: last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate) if last_purchase: out.update(last_purchase) return out
def validate_for_items(self, obj): check_list, chk_dupl_itm=[],[] for d in getlist( obj.doclist, obj.fname): # validation for valid qty if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): msgprint("Please enter valid qty for item %s" % cstr(d.item_code)) raise Exception # udpate with latest quantities bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0, 'billed_qty': 0} if d.doctype == 'Purchase Receipt Item': f_lst.pop('received_qty') for x in f_lst : if d.fields.has_key(x): d.fields[x] = f_lst[x] item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s", d.item_code) if not item: msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True) from stock.utils import validate_end_of_life validate_end_of_life(d.item_code, item[0][3]) # validate stock item if item[0][0]=='Yes' and d.qty and not d.warehouse: msgprint("Warehouse is mandatory for %s, since it is a stock item" % d.item_code, raise_exception=1) # validate purchase item if item[0][1] != 'Yes' and item[0][2] != 'Yes': msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True) if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname: # check warehouse, uom in previous doc and in current doc are same. data = sql("select item_code, warehouse, uom from `tab%s` where name = '%s'" % ( self.doctype_dict[d.prevdoc_doctype], d.prevdoc_detail_docname), as_dict = 1) if not data: msgprint("Please fetch data in Row " + cstr(d.idx) + " once again or please contact Administrator.") raise Exception # Check if Item Code has been modified. if not cstr(data[0]['item_code']) == cstr(d.item_code): msgprint("Please check Item %s is not present in %s %s ." % (d.item_code, d.prevdoc_doctype, d.prevdoc_docname)) raise Exception # Check if Warehouse has been modified. if not cstr(data[0]['warehouse']) == cstr(d.warehouse): msgprint("Please check warehouse %s of Item %s which is not present in %s %s ." % \ (d.warehouse, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True) # Check if UOM has been modified. if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request': msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % \ (d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True) # list criteria that should not repeat if item is stock item e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or ''] # if is not stock item f = [d.schedule_date, d.item_code, d.description] ch = sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code) if ch and ch[0][0] == 'Yes': # check for same items if e in check_list: msgprint("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n Please change any of the field value to enter the item twice""" % d.item_code, raise_exception = 1) else: check_list.append(e) elif ch and ch[0][0] == 'No': # check for same items if f in chk_dupl_itm: msgprint("""Item %s has been entered more than once with same description, schedule date.\n Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1) else: chk_dupl_itm.append(f)