def get_item_details(self, args=None): item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and (ifnull(end_of_life,'0000-00-00')='0000-00-00' or end_of_life > now())""", (args.get('item_code')), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = { 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'expense_account' : args.get("expense_account") \ or frappe.db.get_value("Company", args.get("company"), "stock_adjustment_account"), 'cost_center' : get_default_cost_center(args, item), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'incoming_rate' : 0 } stock_and_rate = args.get('warehouse') and self.get_warehouse_details(args) or {} ret.update(stock_and_rate) return ret
def get_item_details(self, args=None): item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and (ifnull(end_of_life,'0000-00-00')='0000-00-00' or end_of_life > now())""", (args.get('item_code')), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = { 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'expense_account' : args.get("expense_account") \ or frappe.db.get_value("Company", args.get("company"), "stock_adjustment_account"), 'cost_center' : get_default_cost_center(args, item), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'incoming_rate' : 0 } stock_and_rate = args.get('warehouse') and self.get_warehouse_details(args) or {} ret.update(stock_and_rate) return ret
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group, has_serial_no, has_batch_no, sample_quantity from `tabItem` where name = %s and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (args.get('item_code'), nowdate()), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = frappe._dict({ 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'expense_account' : args.get("expense_account"), 'cost_center' : get_default_cost_center(args, item), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'basic_rate' : 0, 'serial_no' : '', 'has_serial_no' : item.has_serial_no, 'has_batch_no' : item.has_batch_no, 'sample_quantity' : item.sample_quantity }) for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # update uom if args.get("uom") and for_update: ret.update(get_uom_details(args.get('item_code'), args.get('uom'), args.get('qty'))) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value("Company", self.company, "stock_adjustment_account") args['posting_date'] = self.posting_date args['posting_time'] = self.posting_time stock_and_rate = get_warehouse_details(args) if args.get('warehouse') else {} ret.update(stock_and_rate) # automatically select batch for outgoing item if (args.get('s_warehouse', None) and args.get('qty') and ret.get('has_batch_no') and not args.get('batch_no')): args.batch_no = get_batch_no(args['item_code'], args['s_warehouse'], args['qty']) return ret
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group, has_serial_no, has_batch_no, sample_quantity from `tabItem` where name = %s and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (args.get('item_code'), nowdate()), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = frappe._dict({ 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'expense_account' : args.get("expense_account"), 'cost_center' : get_default_cost_center(args, item), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'basic_rate' : 0, 'serial_no' : '', 'has_serial_no' : item.has_serial_no, 'has_batch_no' : item.has_batch_no, 'sample_quantity' : item.sample_quantity }) for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # update uom if args.get("uom") and for_update: ret.update(get_uom_details(args.get('item_code'), args.get('uom'), args.get('qty'))) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value("Company", self.company, "stock_adjustment_account") args['posting_date'] = self.posting_date args['posting_time'] = self.posting_time stock_and_rate = get_warehouse_details(args) if args.get('warehouse') else {} ret.update(stock_and_rate) # automatically select batch for outgoing item if (args.get('s_warehouse', None) and args.get('qty') and ret.get('has_batch_no') and not args.get('batch_no')): args.batch_no = get_batch_no(args['item_code'], args['s_warehouse'], args['qty']) return ret
def get_item_cost_center(item_code=None, company=None, project=None, customer=None): cost_center = frappe.get_cached_value("Company", company, "cost_center") if not item_code: return cost_center item_defaults = get_item_defaults(item_code, company) item_group_defaults = get_item_group_defaults(item_code, company) args = { "project": project, "customer": customer, "cost_center": cost_center, } return get_default_cost_center(args, item_defaults, item_group_defaults, company)
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql( """select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (args.get("item_code"), nowdate()), as_dict=1, ) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = { "uom": item.stock_uom, "stock_uom": item.stock_uom, "description": item.description, "image": item.image, "item_name": item.item_name, "expense_account": args.get("expense_account"), "cost_center": get_default_cost_center(args, item), "qty": 0, "transfer_qty": 0, "conversion_factor": 1, "batch_no": "", "actual_qty": 0, "basic_rate": 0, } for d in [ ["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"], ]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # update uom if args.get("uom") and for_update: ret.update(self.get_uom_details(args)) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value("Company", self.company, "stock_adjustment_account") args["posting_date"] = self.posting_date args["posting_time"] = self.posting_time stock_and_rate = args.get("warehouse") and get_warehouse_details(args) or {} ret.update(stock_and_rate) return ret
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql("""select i.name, i.stock_uom, i.description, i.image, i.item_name, i.item_group, i.has_batch_no, i.sample_quantity, i.has_serial_no, id.expense_account, id.buying_cost_center from `tabItem` i LEFT JOIN `tabItem Default` id ON i.name=id.parent and id.company=%s where i.name=%s and i.disabled=0 and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""", (self.company, args.get('item_code'), nowdate()), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] item_group_defaults = get_item_group_defaults(item.name, self.company) ret = frappe._dict({ 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'cost_center' : get_default_cost_center(args, item, item_group_defaults, self.company), 'qty' : args.get("qty"), 'transfer_qty' : args.get('qty'), 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'basic_rate' : 0, 'serial_no' : '', 'has_serial_no' : item.has_serial_no, 'has_batch_no' : item.has_batch_no, 'sample_quantity' : item.sample_quantity }) # update uom if args.get("uom") and for_update: ret.update(get_uom_details(args.get('item_code'), args.get('uom'), args.get('qty'))) args['posting_date'] = self.posting_date args['posting_time'] = self.posting_time stock_and_rate = get_warehouse_details(args) if args.get('warehouse') else {} ret.update(stock_and_rate) # automatically select batch for outgoing item if (args.get('s_warehouse', None) and args.get('qty') and ret.get('has_batch_no') and not args.get('batch_no')): args.batch_no = get_batch_no(args['item_code'], args['s_warehouse'], args['qty']) return ret
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql( """select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (args.get('item_code'), nowdate()), as_dict=1) if not item: frappe.throw( _("Item {0} is not active or end of life has been reached"). format(args.get("item_code"))) item = item[0] ret = { 'uom': item.stock_uom, 'stock_uom': item.stock_uom, 'description': item.description, 'image': item.image, 'item_name': item.item_name, 'expense_account': args.get("expense_account"), 'cost_center': get_default_cost_center(args, item), 'qty': 0, 'transfer_qty': 0, 'conversion_factor': 1, 'batch_no': '', 'actual_qty': 0, 'basic_rate': 0 } for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # update uom if args.get("uom") and for_update: ret.update(self.get_uom_details(args)) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value( "Company", self.company, "stock_adjustment_account") stock_and_rate = args.get('warehouse') and self.get_warehouse_details( args) or {} ret.update(stock_and_rate) return ret
def get_item_details(self, args=None, for_update=False): item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and (ifnull(end_of_life,'0000-00-00')='0000-00-00' or end_of_life > now())""", (args.get('item_code')), as_dict = 1) if not item: frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code"))) item = item[0] ret = { 'uom' : item.stock_uom, 'stock_uom' : item.stock_uom, 'description' : item.description, 'image' : item.image, 'item_name' : item.item_name, 'expense_account' : args.get("expense_account"), 'cost_center' : get_default_cost_center(args, item), 'qty' : 0, 'transfer_qty' : 0, 'conversion_factor' : 1, 'batch_no' : '', 'actual_qty' : 0, 'basic_rate' : 0 } for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # update uom if args.get("uom") and for_update: ret.update(self.get_uom_details(args)) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value("Company", self.company, "stock_adjustment_account") stock_and_rate = args.get('warehouse') and self.get_warehouse_details(args) or {} ret.update(stock_and_rate) return ret
def get_item_details(args=None, for_update=False): arg = json.loads(args) #print"##############################",arg item = frappe.db.sql("""select stock_uom, description, image, item_name, expense_account, buying_cost_center, item_group from `tabItem` where name = %s and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (arg.get('item_code'), nowdate()), as_dict=1) query = frappe.db.sql( """SELECT `item`,`name`,`batch_id` as batch_no, date(production_date) as production_date, date(expiry_date) as expiry_date from `tabBatch` where item='{0}' and DATEDIFF(expiry_date, date(now())) >= 2""" .format(arg.get('item_code')), as_dict=1) #print "%%%%%%%%%%%%%%%%%%%%%%%%%%",query,"\n\n\n",item if query and item and arg.get('purpose') == 'Material Receipt' and arg.get( 'update_stock') == True: batches = {} d = {} for i in query: d[i['item']] = min([ row['expiry_date'] for row in query if row['item'] == i['item'] ]) for i in query: if i['expiry_date'] in d.values(): batches['batches'] = i print "$$$$$$$$$$$$$$$$", batches.get('batches') item[0].update(batches.get('batches')) if not item: frappe.throw( _("Item {0} is not active or end of life has been reached").format( arg.get("item_code"))) item = item[0] ret = { 'uom': item.stock_uom, 'stock_uom': item.stock_uom, 'description': item.description, 'image': item.image, 'item_name': item.item_name, 'expense_account': arg.get("expense_account"), 'cost_center': get_default_cost_center(arg, item), 'qty': 0, 'transfer_qty': 0, 'conversion_factor': 1, 'batch_no': item.batch_no if arg.get('update_stock') == True else '', 'actual_qty': 0, 'basic_rate': 0, 'serial_no': '', 'production_date': item.production_date if arg.get('update_stock') == True else '', 'expiry_date': item.expiry_date if arg.get('update_stock') == True else '' } for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and arg.get('company') != company): ret[d[1]] = frappe.db.get_value("Company", arg.get('company'), d[2]) if d[2] else None # update uom if arg.get("uom") and for_update: ret.update(get_uom_details(arg)) if not ret["expense_account"]: ret["expense_account"] = frappe.db.get_value( "Company", arg.get('company'), "stock_adjustment_account") arg['posting_date'] = arg.get('posting_date') arg['posting_time'] = arg.get('posting_time') stock_and_rate = arg.get('warehouse') and get_warehouse_details(arg) or {} ret.update(stock_and_rate) # print ret, "------------" return ret
def get_item_details(self, args=None, for_update=False): # referenced from stock_entry.py # is called when item_code is changed item = frappe.db.sql( """select stock_uom, description, image, item_name, item_group, expense_account, buying_cost_center from `tabItem` where name = %s and disabled = 0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", (args.get('item_code'), nowdate()), as_dict=1) if not item: frappe.throw( _("Item {0} is not active or end of life has been reached."). format(args.get('item_code'))) item = item[0] # expense_account and cost_centers are not applicable in warehouse transfer. ret = { 'uom': item.stock_uom, 'stock_uom': item.stock_uom, 'description': item.description, 'image': item.image, 'item_name': item.item_name, 'expense_account': args.get("expense_account"), 'cost_center': get_default_cost_center(args, item), 'qty': 0, 'transfer_qty': 0, 'conversion_factor': 1, 'actual_qty': 0, 'basic_rate': 0, 'batch_no': '', 'serial_no': '' } # setting default expense account or cost center for the company unless specified # also validates if the account or cost center is coming from the current company for d in [["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"]]: company = frappe.db.get_value(d[0], ret.get(d[1]), "company") if not ret[d[1]] or (company and self.company != company): ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None # V8 # whitelisted methods # from erpnext.stock.doctype.stock_entry.stock_entry import get_uom_details, get_warehouse_details # update uom if args.get('uom') and for_update: ret.update( get_uom_details(args.get('item_code'), args.get('uom'), args.get('qty'))) args["posting_time"] = self.posting_time args["posting_date"] = self.posting_date stock_and_rate = args.get('warehouse') and get_warehouse_details( args) or {} ret.update(stock_and_rate) return ret
def _get_basic_details(args, item): """ :param args: { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "price_list_uom_dependant": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "", barcode: "", serial_no: "", currency: "", update_stock: "", price_list: "", company: "", order_type: "", is_pos: "", project: "", qty: "", stock_qty: "", conversion_factor: "" } :param item: `item_code` of Item object :return: frappe._dict """ if not item: item = frappe.get_doc("Item", args.get("item_code")) if item.variant_of: item.update_template_tables() from frappe.defaults import get_user_default_as_list user_default_warehouse_list = get_user_default_as_list("Warehouse") user_default_warehouse = (user_default_warehouse_list[0] if len(user_default_warehouse_list) == 1 else "") item_defaults = get_item_defaults(item.name, args.company) item_group_defaults = get_item_group_defaults(item.name, args.company) warehouse = (args.get("set_warehouse") or user_default_warehouse or item_defaults.get("default_warehouse") or item_group_defaults.get("default_warehouse") or args.warehouse) if not args.get("material_request_type"): args["material_request_type"] = frappe.db.get_value( "Material Request", args.get("name"), "material_request_type", cache=True) # Set the UOM to the Default Sales UOM or Default Purchase UOM if configured in the Item Master if not args.uom: args.uom = item.purchase_uom if item.purchase_uom else item.stock_uom out = frappe._dict({ "item_code": item.name, "item_name": item.item_name, "description": cstr(item.description).strip(), "image": cstr(item.image).strip(), "warehouse": warehouse, "income_account": get_default_income_account(args, item_defaults, item_group_defaults), "expense_account": get_default_expense_account(args, item_defaults, item_group_defaults), "cost_center": get_default_cost_center(args, item_defaults, item_group_defaults), "has_serial_no": item.has_serial_no, "has_batch_no": item.has_batch_no, "batch_no": None, "item_tax_rate": json.dumps(dict( ([d.tax_type, d.tax_rate] for d in item.get("taxes")))), "uom": args.uom, "min_order_qty": flt(item.min_order_qty), "qty": args.qty or 1.0, "stock_qty": args.qty or 1.0, "price_list_rate": 0.0, "base_price_list_rate": 0.0, "rate": 0.0, "base_rate": 0.0, "amount": 0.0, "base_amount": 0.0, "net_rate": 0.0, "net_amount": 0.0, "discount_percentage": 0.0, "supplier": get_default_supplier(args, item_defaults, item_group_defaults), "update_stock": args.get("update_stock") if args.get("doctype") in ["Sales Invoice", "Purchase Invoice"] else 0, "delivered_by_supplier": item.delivered_by_supplier if args.get("doctype") in ["Sales Order", "Sales Invoice"] else 0, "is_fixed_asset": item.is_fixed_asset, "weight_per_unit": item.weight_per_unit, "weight_uom": item.weight_uom, "last_purchase_rate": item.last_purchase_rate if args.get("doctype") in ["Purchase Order"] else 0, "transaction_date": args.get("transaction_date"), }) if item.get("enable_deferred_revenue") or item.get( "enable_deferred_expense"): out.update(calculate_service_end_date(args, item)) # calculate conversion factor if item.stock_uom == args.uom: out.conversion_factor = 1.0 else: out.conversion_factor = args.conversion_factor or get_conversion_factor( item.name, args.uom).get("conversion_factor") args.conversion_factor = out.conversion_factor out.stock_qty = out.qty * out.conversion_factor # calculate last purchase rate from erpnext.buying.doctype.purchase_order.purchase_order import ( item_last_purchase_rate, ) out.last_purchase_rate = item_last_purchase_rate(args.name, args.conversion_rate, item.name, out.conversion_factor) # if default specified in item is for another company, fetch from company for d in [ ["Account", "income_account", "default_income_account"], ["Account", "expense_account", "default_expense_account"], ["Cost Center", "cost_center", "cost_center"], ["Warehouse", "warehouse", ""], ]: if not out[d[1]]: out[d[1]] = (frappe.get_cached_value("Company", args.company, d[2]) if d[2] else None) for fieldname in ("item_name", "item_group", "barcodes", "brand", "stock_uom"): out[fieldname] = item.get(fieldname) meta = frappe.get_meta(args.child_doctype) if meta.get_field("barcode"): update_barcode_value(out) return out