From af5df668471891b2dcd85464a5d8ad430bdf444d Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 20 Jun 2013 15:00:53 +0530 Subject: [PATCH 1/2] to avoid merge conflict --- controllers/trends.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/trends.py b/controllers/trends.py index 4edb7845ceb..08babb73323 100644 --- a/controllers/trends.py +++ b/controllers/trends.py @@ -74,7 +74,6 @@ def get_data(filters, tab, details): "%s", cond, details["basedon"]), (filters.get("company"), filters["fiscal_year"]), as_list=1) - for d in range(len(data1)): #to add blanck column dt = data1[d] @@ -88,11 +87,10 @@ def get_data(filters, tab, details): """%(sel_col, tab[0], tab[1], details["sup_tab"], "%s", "%s", details["basedon"], "%s"), (filters.get("company"), filters.get("fiscal_year"), data1[d][0]), as_list=1) - for i in range(len(row)): des = ['' for q in range(len(details["columns"]))] - #get data for each group_by filter + #get data for group_by filter row1 = webnotes.conn.sql(""" select %s , %s from `%s` t1, `%s` t2 %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 @@ -100,7 +98,6 @@ def get_data(filters, tab, details): "%s", "%s", sel_col, "%s", details["basedon"], "%s"), (filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1) - des[ind] = row[i] for j in range(1,len(details["columns"])-inc): des[j+inc] = row1[0][j] @@ -123,7 +120,6 @@ def get_mon(date): return (datetime.strptime(date, '%Y-%m-%d')).strftime("%b") def period_wise_colums_query(filters, trans): - from datetime import datetime query_details = '' pwc = [] @@ -161,8 +157,12 @@ def period_wise_colums_query(filters, trans): elif filters.get("period") == "Quarterly": - first_qsd, second_qsd, third_qsd, fourth_qsd = year_start_date, add_months(year_start_date,3), add_months(year_start_date,6), add_months(year_start_date,9) - first_qed, second_qed, third_qed, fourth_qed = add_days(add_months(first_qsd,3),-1), add_days(add_months(second_qsd,3),-1), add_days(add_months(third_qsd,3),-1), add_days(add_months(fourth_qsd,3),-1) + first_qsd, second_qsd = year_start_date, add_months(year_start_date,3) + third_qsd, fourth_qsd = add_months(year_start_date,6), add_months(year_start_date,9) + + first_qed, second_qed = add_days(add_months(first_qsd,3),-1), add_days(add_months(second_qsd,3),-1) + third_qed, fourth_qed = add_days(add_months(third_qsd,3),-1), add_days(add_months(fourth_qsd,3),-1) + bet_dates = [[first_qsd,first_qed],[second_qsd,second_qed],[third_qsd,third_qed],[fourth_qsd,fourth_qed]] pwc = [get_mon(first_qsd)+"-"+get_mon(first_qed)+" (Qty):Float:120", get_mon(first_qsd)+"-"+get_mon(first_qed)+"(Amt):Currency:120", From 2b02f1410a3e726c4d34da84f8c2391d8048c4a3 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 21 Jun 2013 10:46:26 +0530 Subject: [PATCH 2/2] Trends Analyzer cleanup finished --- controllers/trends.py | 94 ++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/controllers/trends.py b/controllers/trends.py index bbab01eb2a0..acbc744ae6a 100644 --- a/controllers/trends.py +++ b/controllers/trends.py @@ -23,18 +23,20 @@ def get_columns(filters, trans): validate_filters(filters) # 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 period_cols, period_select = period_wise_colums_query(filters, trans) # get conditions for grouping filter cond 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: - 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, - "group_by": based_on_group_by, "grbc": group_by_cols, "sup_tab": addl_tables, "trans": trans} + conditions = {"based_on_select": based_on_details["based_on_select"], "period_wise_select": period_select, + "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 @@ -73,7 +75,7 @@ def get_data(filters, conditions): where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 %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"), 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 where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %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"), 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 and t1.docstatus = 1 and %s = %s and %s = %s """ % (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) des[ind] = row[i] @@ -108,12 +110,12 @@ def get_data(filters, conditions): data.append(des) 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 where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 %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"), filters.get("fiscal_year")), as_list=1) @@ -191,58 +193,66 @@ def get_period_month_ranges(period, fiscal_year): return period_month_ranges 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": - bon = ["Item:Link/Item:120", "Item Name:Data:120"] - query_details = "t2.item_code, t2.item_name," - based = 't2.item_code' + based_on_details["based_on_cols"] = ["Item:Link/Item:120", "Item Name:Data:120"] + based_on_details["based_on_select"] = "t2.item_code, t2.item_name," + based_on_details["based_on_group_by"] = 't2.item_code' + based_on_details["addl_tables"] = '' elif based_on == "Item Group": - bon = ["Item Group:Link/Item Group:120"] - query_details = "t2.item_group," - based = 't2.item_group' + based_on_details["based_on_cols"] = ["Item Group:Link/Item Group:120"] + based_on_details["based_on_select"] = "t2.item_group," + based_on_details["based_on_group_by"] = 't2.item_group' + based_on_details["addl_tables"] = '' elif based_on == "Customer": - bon = ["Customer:Link/Customer:120", "Territory:Link/Territory:120"] - query_details = "t1.customer_name, t1.territory, " - based = 't1.customer_name' + based_on_details["based_on_cols"] = ["Customer:Link/Customer:120", "Territory:Link/Territory:120"] + based_on_details["based_on_select"] = "t1.customer_name, t1.territory, " + based_on_details["based_on_group_by"] = 't1.customer_name' + based_on_details["addl_tables"] = '' elif based_on == "Customer Group": - bon = ["Customer Group:Link/Customer Group"] - query_details = "t1.customer_group," - based = 't1.customer_group' - + based_on_details["based_on_cols"] = ["Customer Group:Link/Customer Group"] + based_on_details["based_on_select"] = "t1.customer_group," + based_on_details["based_on_group_by"] = 't1.customer_group' + based_on_details["addl_tables"] = '' + elif based_on == 'Supplier': - bon = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:120"] - query_details = "t1.supplier, t3.supplier_type," - based = 't1.supplier' - sup_tab = ',`tabSupplier` t3' + based_on_details["based_on_cols"] = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:140"] + based_on_details["based_on_select"] = "t1.supplier, t3.supplier_type," + based_on_details["based_on_group_by"] = 't1.supplier' + based_on_details["addl_tables"] = ',`tabSupplier` t3' elif based_on == 'Supplier Type': - bon = ["Supplier Type:Link/Supplier Type:120"] - query_details = "t3.supplier_type," - based = 't3.supplier_type' - sup_tab =',`tabSupplier` t3' + based_on_details["based_on_cols"] = ["Supplier Type:Link/Supplier Type:140"] + based_on_details["based_on_select"] = "t3.supplier_type," + based_on_details["based_on_group_by"] = 't3.supplier_type' + based_on_details["addl_tables"] =',`tabSupplier` t3' elif based_on == "Territory": - bon = ["Territory:Link/Territory:120"] - query_details = "t1.territory," - based = 't1.territory' + based_on_details["based_on_cols"] = ["Territory:Link/Territory:120"] + based_on_details["based_on_select"] = "t1.territory," + based_on_details["based_on_group_by"] = 't1.territory' + based_on_details["addl_tables"] = '' elif based_on == "Project": if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']: - bon = ["Project:Link/Project:120"] - query_details = "t1.project_name," - based = 't1.project_name' + based_on_details["based_on_cols"] = ["Project:Link/Project:120"] + based_on_details["based_on_select"] = "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']: - bon = ["Project:Link/Project:120"] - query_details = "t2.project_name," - based = 't2.project_name' + based_on_details["based_on_cols"] = ["Project:Link/Project:120"] + based_on_details["based_on_select"] = "t2.project_name," + based_on_details["based_on_group_by"] = 't2.project_name' + based_on_details["addl_tables"] = '' else: 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): if group_by: