Function renaming, code cleaning and minor fixes (#15938)

This commit is contained in:
Deepesh Garg 2018-11-13 11:28:58 +05:30 committed by Nabin Hait
parent a695dad525
commit b65bb5df2e

View File

@ -3,17 +3,16 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe import _, scrub
from frappe.utils import getdate
from erpnext.selling.report.sales_analytics.sales_analytics import (get_period_date_ranges,get_period)
from erpnext.stock.report.stock_analytics.stock_analytics import (get_period_date_ranges, get_period)
def execute(filters=None):
columns = get_columns(filters)
data, chart = get_data(filters,columns)
return columns, data,None ,chart
data, chart = get_data(filters, columns)
return columns, data, None , chart
def get_columns(filters):
columns =[
{
"label": _("Status"),
@ -22,122 +21,113 @@ def get_columns(filters):
"width": 140
}]
ranges = get_period_date_ranges(period=filters["range"], year_start_date = filters["from_date"],year_end_date=filters["to_date"])
ranges = get_period_date_ranges(filters)
for dummy, end_date in ranges:
label = field_name = get_period(end_date,filters["range"])
period = get_period(end_date, filters)
columns.append(
{
"label": _(label),
"fieldname": field_name,
columns.append({
"label": _(period),
"fieldname": scrub(period),
"fieldtype": "Float",
"width": 120
},
)
})
return columns
def get_data_list(filters,entry):
data_list = {
"All Work Orders" : {},
"Not Started" : {},
"Overdue" : {},
"Pending" : {},
"Completed" : {}
def get_periodic_data(filters, entry):
periodic_data = {
"All Work Orders": {},
"Not Started": {},
"Overdue": {},
"Pending": {},
"Completed": {}
}
ranges = get_period_date_ranges(period=filters["range"], year_start_date = filters["from_date"],year_end_date=filters["to_date"])
ranges = get_period_date_ranges(filters)
for from_date,end_date in ranges:
period = get_period(end_date,filters["range"])
for from_date, end_date in ranges:
period = get_period(end_date, filters)
for d in entry:
if getdate(d.creation) <= getdate(from_date) or getdate(d.creation) <= getdate(end_date) :
data_list = update_data_list(data_list,"All Work Orders",period)
periodic_data = update_periodic_data(periodic_data, "All Work Orders", period)
if d.status == 'Completed':
if getdate(d.actual_end_date) < getdate(from_date) or getdate(d.modified) < getdate(from_date):
data_list = update_data_list(data_list, "Completed",period)
periodic_data = update_periodic_data(periodic_data, "Completed", period)
elif getdate(d.actual_start_date) < getdate(from_date) :
data_list = update_data_list(data_list, "Pending", period)
periodic_data = update_periodic_data(periodic_data, "Pending", period)
elif getdate(d.planned_start_date) < getdate(from_date) :
data_list = update_data_list(data_list, "Overdue", period)
periodic_data = update_periodic_data(periodic_data, "Overdue", period)
else:
data_list = update_data_list(data_list, "Not Started", period)
periodic_data = update_periodic_data(periodic_data, "Not Started", period)
elif d.status == 'In Process':
if getdate(d.actual_start_date) < getdate(from_date) :
data_list = update_data_list(data_list, "Pending", period)
periodic_data = update_periodic_data(periodic_data, "Pending", period)
elif getdate(d.planned_start_date) < getdate(from_date) :
data_list = update_data_list(data_list, "Overdue", period)
periodic_data = update_periodic_data(periodic_data, "Overdue", period)
else:
data_list = update_data_list(data_list, "Not Started", period)
periodic_data = update_periodic_data(periodic_data, "Not Started", period)
elif d.status == 'Not Started':
if getdate(d.planned_start_date) < getdate(from_date) :
data_list = update_data_list(data_list, "Overdue", period)
periodic_data = update_periodic_data(periodic_data, "Overdue", period)
else:
data_list = update_data_list(data_list, "Not Started", period)
return data_list
periodic_data = update_periodic_data(periodic_data, "Not Started", period)
return periodic_data
def update_data_list(data_list, status, period):
if data_list.get(status).get(period):
data_list[status][period] += 1
def update_periodic_data(periodic_data, status, period):
if periodic_data.get(status).get(period):
periodic_data[status][period] += 1
else:
data_list[status][period] = 1
periodic_data[status][period] = 1
return data_list
def get_data(filters,columns):
return periodic_data
def get_data(filters, columns):
data = []
entry = frappe.get_all("Work Order",
fields=["creation", "modified", "actual_start_date", "actual_end_date", "planned_start_date", "planned_end_date", "status"],
filters={"docstatus" : 1, "company" : filters["company"] })
filters={"docstatus": 1, "company": filters["company"] })
data_list = get_data_list(filters,entry)
periodic_data = get_periodic_data(filters,entry)
labels = ["All Work Orders", "Not Started", "Overdue", "Pending", "Completed"]
chart_data = get_chart_data(data_list,columns)
ranges = get_period_date_ranges(period=filters["range"], year_start_date = filters["from_date"],year_end_date=filters["to_date"])
chart_data = get_chart_data(periodic_data,columns)
ranges = get_period_date_ranges(filters)
for label in labels:
work = {}
work["Status"] = label
for dummy,end_date in ranges:
period = get_period(end_date,filters["range"])
if data_list.get(label).get(period):
work[period] = data_list.get(label).get(period)
period = get_period(end_date, filters)
if periodic_data.get(label).get(period):
work[scrub(period)] = periodic_data.get(label).get(period)
else:
work[period] = 0.0
work[scrub(period)] = 0.0
data.append(work)
return data, chart_data
def get_chart_data(data_list,columns):
def get_chart_data(periodic_data, columns):
labels = [d.get("label") for d in columns[1:]]
all_data, not_start, overdue, pending, completed = [], [], [] , [], []
datasets = []
for d in labels:
all_data.append(data_list.get("All Work Orders").get(d))
not_start.append(data_list.get("Not Started").get(d))
overdue.append(data_list.get("Overdue").get(d))
pending.append(data_list.get("Pending").get(d))
completed.append(data_list.get("Completed").get(d))
all_data.append(periodic_data.get("All Work Orders").get(d))
not_start.append(periodic_data.get("Not Started").get(d))
overdue.append(periodic_data.get("Overdue").get(d))
pending.append(periodic_data.get("Pending").get(d))
completed.append(periodic_data.get("Completed").get(d))
datasets.append({'name':'All Work Orders', 'values': all_data})
datasets.append({'name':'Not Started', 'values': not_start})
@ -148,10 +138,9 @@ def get_chart_data(data_list,columns):
chart = {
"data": {
'labels': labels,
'datasets':datasets
'datasets': datasets
}
}
chart["type"] = "line"
return chart