def get(chart_name=None, chart=None, no_cache=None, filters=None, from_date=None, to_date=None, timespan=None, time_interval=None, heatmap_year=None): labels, datapoints = [], [] filters = frappe.parse_json(filters) warehouse_filters = [['is_group', '=', 0]] if filters and filters.get("company"): warehouse_filters.append(['company', '=', filters.get("company")]) warehouses = frappe.get_list("Warehouse", fields=['name'], filters=warehouse_filters, order_by='name') for wh in warehouses: balance = get_stock_value_from_bin(warehouse=wh.name) wh["balance"] = balance[0][0] warehouses = [x for x in warehouses if not (x.get('balance') == None)] if not warehouses: return [] sorted_warehouse_map = sorted(warehouses, key=lambda i: i['balance'], reverse=True) if len(sorted_warehouse_map) > 10: sorted_warehouse_map = sorted_warehouse_map[:10] for warehouse in sorted_warehouse_map: labels.append(_(warehouse.get("name"))) datapoints.append(warehouse.get("balance")) return { "labels": labels, "datasets": [{ "name": _("Stock Value"), "values": datapoints }], "type": "bar" }
def get_children(doctype, parent=None, company=None, is_root=False): from erpnext.stock.utils import get_stock_value_from_bin if is_root: parent = "" warehouses = frappe.db.sql("""select name as value, is_group as expandable from `tabWarehouse` where docstatus < 2 and ifnull(`parent_warehouse`,'') = %s and (`company` = %s or company is null or company = '') order by name""", (parent, company), as_dict=1) # return warehouses for wh in warehouses: wh["balance"] = get_stock_value_from_bin(warehouse=wh.value) return warehouses
def add_stocks(items, file): for item in items: # if item["Location"] == "DCL House, Plot 1299 Fumilayo Ransome Kuti Way, Area 3, PMB 690 Garki, Abuja": # to_warehouse = "DCLWarehouse - Abuja - DCL" # elif item[ # "Location"] == "DCL Laboratory Products Ltd, Plot 5 Block 4 Etal Avenue off Kudirat Abiola Way by NNPC Lagos NG - DCL": # to_warehouse = "Lagos Warehouse - DCL" # else: to_warehouse = item["Location"] # def get_stock_value_from_bin(warehouse="DCLWarehouse - Abuja - DCL", item_code=item["item_code"]): bal = get_stock_value_from_bin(warehouse=to_warehouse, item_code=item["item_code"]) print " * * * * Check Bin * * * *" print " " + str(bal[0][0]), item['qty'] print " " + item['item_code'] date = None time = None if item["DatePaid"]: print " ", item["DatePaid"].date(), item["DatePaid"].time( ) date = item["DatePaid"].date() time = item["DatePaid"].time() elif item["OrderDate"]: date = item["OrderDate"].date() time = item["OrderDate"].time() if bal[0][0] < item['qty'] or bal[0][0] == None or bal[0][0] == 0: diff = 0 if bal[0][0] != None: diff = bal[0][0] make_stock_entry(item_code=item["item_code"], qty=abs(float(item["qty"]) - diff), to_warehouse=to_warehouse, valuation_rate=1, remarks="This is affected by data import. " + file, posting_date=date, posting_time=time, set_posting_time=1, inflow_file=file) frappe.db.commit() print "Stock entry created."
def get_children(doctype, parent=None, company=None, is_root=False): from erpnext.stock.utils import get_stock_value_from_bin if is_root: parent = "" fields = ['name as value', 'is_group as expandable'] filters = [ ['docstatus', '<', '2'], ['ifnull(`parent_warehouse`, "")', '=', parent], ['company', 'in', (company, None,'')] ] warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by='name') # return warehouses for wh in warehouses: wh["balance"] = get_stock_value_from_bin(warehouse=wh.value) return warehouses
def get_children(doctype, parent=None, company=None, is_root=False): from erpnext.stock.utils import get_stock_value_from_bin if is_root: parent = "" fields = ['name as value', 'is_group as expandable'] filters = [ ['docstatus', '<', '2'], ['ifnull(`parent_warehouse`, "")', '=', parent], ['company', 'in', (company, None,'')] ] warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by='name') # return warehouses for wh in warehouses: wh["balance"] = get_stock_value_from_bin(warehouse=wh.value) if company: wh["company_currency"] = frappe.db.get_value('Company', company, 'default_currency') return warehouses
def start_import(): import csv import os current_customer = "" current_order = "" SI_dict = {} SI_items = [] paid_and_fulfilled_items = [] fulfilled_items = [] paid_items = [] input_file = csv.DictReader(open(os.path.dirname(os.path.abspath(__file__))+'/data/inFlow_StockLevels.csv')) # current_customer = input_file[0]["Customer"] income_accounts = "5111 - Cost of Goods Sold - DCL" # income_accounts = "Sales - J" cost_centers = "Main - DCL" # cost_centers = "Main - J" rows = list(input_file) total_paid = 0.0 # print rows totalrows = len(rows) for i,row in enumerate(rows): # print row # from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry #/home/jvfiel/frappe-v11/apps/dcl/dcl/inflow_import/stock/__init__.py # for item in SI_items: #def get_stock_value_from_bin(warehouse="DCLWarehouse - Abuja - DCL", item_code=item["item_code"]): item = row print item bal = get_stock_value_from_bin(warehouse="DCLWarehouse - Abuja - DCL", item_code=item["Item"]) print " * * * * Check Bin * * * *" # print " "+str(bal[0][0]),item['qty'] # print " "+item['item_code'] # if bal[0][0] < item['qty'] or bal[0][0] == None or bal[0][0] == 0: # diff = 0 # if bal[0][0] != None: # diff = bal[0][0] to_warehouse = "" if row["Location"] == "DCL House, Plot 1299 Fumilayo Ransome Kuti Way, Area 3, PMB 690 Garki, Abuja": to_warehouse = "DCLWarehouse - Abuja - DCL" elif row["Location"] == "DCL Laboratory Products Ltd, Plot 5 Block 4 Etal Avenue off Kudirat Abiola Way by NNPC Lagos NG - DCL": to_warehouse = "Lagos Warehouse - DCL" else: to_warehouse = row["Location"] + " - DCL" if float(item["Quantity"]) < 1: exists_cat = frappe.db.sql("""SELECT Count(*) FROM `tabItem` WHERE item_code=%s""", (row["Item"].strip())) # print exists_cat if exists_cat[0][0] == 0: item_code = row["Item"] if row[ "Item"] == "Kerosene stove, four burner pressure type for use with 39L autoclave / steriliser.\nSupplied specifically without top plate (ring) for use only with the autoclave / steam sterilizer.": item_code = "Kerosene Stove" item_dict = {"doctype": "Item", "item_code": item_code.strip(), "description": row["Item"], # "item_group": row["Category"].strip() + " Category" "item_group": "All Item Groups" } SI = frappe.get_doc(item_dict) SI.insert(ignore_permissions=True) frappe.db.commit() make_stock_entry(item_code=item["Item"].strip(),qty=abs(float(item["Quantity"])), to_warehouse=to_warehouse, valuation_rate=1,remarks="This is affected by data import. StockLevels", posting_date=parser.parse("3/15/2017"), posting_time="00:00:00", set_posting_time=1,inflow_file="inFlow_StockLevels.csv" ) frappe.db.commit()