Trends Analyzer cleanup finished

This commit is contained in:
Saurabh 2013-06-21 10:46:26 +05:30
parent f8f68c54d9
commit 2b02f1410a

View File

@ -23,18 +23,20 @@ def get_columns(filters, trans):
validate_filters(filters) validate_filters(filters)
# get conditions for based_on filter cond # get conditions for based_on filter cond
based_on_cols, based_on_select, based_on_group_by, addl_tables = based_wise_colums_query(filters.get("based_on"), trans) based_on_details = based_wise_colums_query(filters.get("based_on"), trans)
# get conditions for periodic filter cond # get conditions for periodic filter cond
period_cols, period_select = period_wise_colums_query(filters, trans) period_cols, period_select = period_wise_colums_query(filters, trans)
# get conditions for grouping filter cond # get conditions for grouping filter cond
group_by_cols = group_wise_column(filters.get("group_by")) group_by_cols = group_wise_column(filters.get("group_by"))
columns = based_on_cols + period_cols + ["Total(Qty):Float:120", "Total(Amt):Currency:120"] columns = based_on_details["based_on_cols"] + period_cols + ["Total(Qty):Float:120", "Total(Amt):Currency:120"]
if group_by_cols: if group_by_cols:
columns = based_on_cols + group_by_cols + period_cols +["Total(Qty):Float:120", "Total(Amt):Currency:120"] columns = based_on_details["based_on_cols"] + group_by_cols + period_cols + \
["Total(Qty):Float:120", "Total(Amt):Currency:120"]
conditions = {"based_on_select": based_on_select, "period_wise_select": period_select, "columns": columns, conditions = {"based_on_select": based_on_details["based_on_select"], "period_wise_select": period_select,
"group_by": based_on_group_by, "grbc": group_by_cols, "sup_tab": addl_tables, "trans": trans} "columns": columns, "group_by": based_on_details["based_on_group_by"], "grbc": group_by_cols, "trans": trans,
"addl_tables": based_on_details["addl_tables"]}
return conditions return conditions
@ -73,7 +75,7 @@ def get_data(filters, conditions):
where t2.parent = t1.name and t1.company = %s where t2.parent = t1.name and t1.company = %s
and t1.fiscal_year = %s and t1.docstatus = 1 %s and t1.fiscal_year = %s and t1.docstatus = 1 %s
group by %s group by %s
""" % (query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s", """ % (query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s",
"%s", cond, conditions["group_by"]), (filters.get("company"), "%s", cond, conditions["group_by"]), (filters.get("company"),
filters["fiscal_year"]),as_list=1) filters["fiscal_year"]),as_list=1)
@ -87,7 +89,7 @@ def get_data(filters, conditions):
row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
and t1.docstatus = 1 and %s = %s and t1.docstatus = 1 and %s = %s
"""%(sel_col, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s", "%s", """%(sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", "%s",
conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"), conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"),
data1[d][0]), as_list=1) data1[d][0]), as_list=1)
@ -99,7 +101,7 @@ def get_data(filters, conditions):
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
and t1.docstatus = 1 and %s = %s and %s = %s and t1.docstatus = 1 and %s = %s and %s = %s
""" % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"], """ % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"],
conditions["sup_tab"], "%s", "%s", sel_col, "%s", conditions["group_by"], "%s"), conditions["addl_tables"], "%s", "%s", sel_col, "%s", conditions["group_by"], "%s"),
(filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1) (filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1)
des[ind] = row[i] des[ind] = row[i]
@ -108,12 +110,12 @@ def get_data(filters, conditions):
data.append(des) data.append(des)
else: else:
webnotes.errprint(["hii", conditions["sup_tab"]]) webnotes.errprint(["hii", conditions["addl_tables"]])
data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s
where t2.parent = t1.name and t1.company = %s where t2.parent = t1.name and t1.company = %s
and t1.fiscal_year = %s and t1.docstatus = 1 %s and t1.fiscal_year = %s and t1.docstatus = 1 %s
group by %s group by %s
"""%(query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s", """%(query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s",
"%s", cond,conditions["group_by"]), (filters.get("company"), "%s", cond,conditions["group_by"]), (filters.get("company"),
filters.get("fiscal_year")), as_list=1) filters.get("fiscal_year")), as_list=1)
@ -191,58 +193,66 @@ def get_period_month_ranges(period, fiscal_year):
return period_month_ranges return period_month_ranges
def based_wise_colums_query(based_on, trans): def based_wise_colums_query(based_on, trans):
sup_tab = '' based_on_details = {}
# based_on_cols, based_on_select, based_on_group_by, addl_tables
if based_on == "Item": if based_on == "Item":
bon = ["Item:Link/Item:120", "Item Name:Data:120"] based_on_details["based_on_cols"] = ["Item:Link/Item:120", "Item Name:Data:120"]
query_details = "t2.item_code, t2.item_name," based_on_details["based_on_select"] = "t2.item_code, t2.item_name,"
based = 't2.item_code' based_on_details["based_on_group_by"] = 't2.item_code'
based_on_details["addl_tables"] = ''
elif based_on == "Item Group": elif based_on == "Item Group":
bon = ["Item Group:Link/Item Group:120"] based_on_details["based_on_cols"] = ["Item Group:Link/Item Group:120"]
query_details = "t2.item_group," based_on_details["based_on_select"] = "t2.item_group,"
based = 't2.item_group' based_on_details["based_on_group_by"] = 't2.item_group'
based_on_details["addl_tables"] = ''
elif based_on == "Customer": elif based_on == "Customer":
bon = ["Customer:Link/Customer:120", "Territory:Link/Territory:120"] based_on_details["based_on_cols"] = ["Customer:Link/Customer:120", "Territory:Link/Territory:120"]
query_details = "t1.customer_name, t1.territory, " based_on_details["based_on_select"] = "t1.customer_name, t1.territory, "
based = 't1.customer_name' based_on_details["based_on_group_by"] = 't1.customer_name'
based_on_details["addl_tables"] = ''
elif based_on == "Customer Group": elif based_on == "Customer Group":
bon = ["Customer Group:Link/Customer Group"] based_on_details["based_on_cols"] = ["Customer Group:Link/Customer Group"]
query_details = "t1.customer_group," based_on_details["based_on_select"] = "t1.customer_group,"
based = 't1.customer_group' based_on_details["based_on_group_by"] = 't1.customer_group'
based_on_details["addl_tables"] = ''
elif based_on == 'Supplier': elif based_on == 'Supplier':
bon = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:120"] based_on_details["based_on_cols"] = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:140"]
query_details = "t1.supplier, t3.supplier_type," based_on_details["based_on_select"] = "t1.supplier, t3.supplier_type,"
based = 't1.supplier' based_on_details["based_on_group_by"] = 't1.supplier'
sup_tab = ',`tabSupplier` t3' based_on_details["addl_tables"] = ',`tabSupplier` t3'
elif based_on == 'Supplier Type': elif based_on == 'Supplier Type':
bon = ["Supplier Type:Link/Supplier Type:120"] based_on_details["based_on_cols"] = ["Supplier Type:Link/Supplier Type:140"]
query_details = "t3.supplier_type," based_on_details["based_on_select"] = "t3.supplier_type,"
based = 't3.supplier_type' based_on_details["based_on_group_by"] = 't3.supplier_type'
sup_tab =',`tabSupplier` t3' based_on_details["addl_tables"] =',`tabSupplier` t3'
elif based_on == "Territory": elif based_on == "Territory":
bon = ["Territory:Link/Territory:120"] based_on_details["based_on_cols"] = ["Territory:Link/Territory:120"]
query_details = "t1.territory," based_on_details["based_on_select"] = "t1.territory,"
based = 't1.territory' based_on_details["based_on_group_by"] = 't1.territory'
based_on_details["addl_tables"] = ''
elif based_on == "Project": elif based_on == "Project":
if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']: if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']:
bon = ["Project:Link/Project:120"] based_on_details["based_on_cols"] = ["Project:Link/Project:120"]
query_details = "t1.project_name," based_on_details["based_on_select"] = "t1.project_name,"
based = 't1.project_name' based_on_details["based_on_group_by"] = 't1.project_name'
based_on_details["addl_tables"] = ''
elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']: elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']:
bon = ["Project:Link/Project:120"] based_on_details["based_on_cols"] = ["Project:Link/Project:120"]
query_details = "t2.project_name," based_on_details["based_on_select"] = "t2.project_name,"
based = 't2.project_name' based_on_details["based_on_group_by"] = 't2.project_name'
based_on_details["addl_tables"] = ''
else: else:
webnotes.msgprint("Project-wise data is not available for Quotation", raise_exception=1) webnotes.msgprint("Project-wise data is not available for Quotation", raise_exception=1)
return bon, query_details, based, sup_tab return based_on_details
def group_wise_column(group_by): def group_wise_column(group_by):
if group_by: if group_by: