Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 6 | from webnotes.utils import add_days, add_months, cstr, getdate |
| 7 | from webnotes import _ |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 8 | |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 9 | def get_columns(filters, trans): |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 10 | validate_filters(filters) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 11 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 12 | # get conditions for based_on filter cond |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 13 | based_on_details = based_wise_colums_query(filters.get("based_on"), trans) |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 14 | # get conditions for periodic filter cond |
| 15 | period_cols, period_select = period_wise_colums_query(filters, trans) |
| 16 | # get conditions for grouping filter cond |
| 17 | group_by_cols = group_wise_column(filters.get("group_by")) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 18 | |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 19 | columns = based_on_details["based_on_cols"] + period_cols + ["Total(Qty):Float:120", "Total(Amt):Currency:120"] |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 20 | if group_by_cols: |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 21 | columns = based_on_details["based_on_cols"] + group_by_cols + period_cols + \ |
| 22 | ["Total(Qty):Float:120", "Total(Amt):Currency:120"] |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 23 | |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 24 | conditions = {"based_on_select": based_on_details["based_on_select"], "period_wise_select": period_select, |
Saurabh | 36cb3ca | 2013-06-21 16:25:28 +0530 | [diff] [blame] | 25 | "columns": columns, "group_by": based_on_details["based_on_group_by"], "grbc": group_by_cols, "trans": trans, |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 26 | "addl_tables": based_on_details["addl_tables"]} |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 27 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 28 | return conditions |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 29 | |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 30 | def validate_filters(filters): |
| 31 | for f in ["Fiscal Year", "Based On", "Period", "Company"]: |
| 32 | if not filters.get(f.lower().replace(" ", "_")): |
| 33 | webnotes.msgprint(f + _(" is mandatory"), raise_exception=1) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 34 | |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 35 | if filters.get("based_on") == filters.get("group_by"): |
| 36 | webnotes.msgprint("'Based On' and 'Group By' can not be same", raise_exception=1) |
| 37 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 38 | def get_data(filters, conditions): |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 39 | data = [] |
| 40 | inc, cond= '','' |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 41 | query_details = conditions["based_on_select"] + conditions["period_wise_select"] |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 42 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 43 | if conditions["based_on_select"] in ["t1.project_name,", "t2.project_name,"]: |
| 44 | cond = 'and '+ conditions["based_on_select"][:-1] +' IS Not NULL' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 45 | |
| 46 | if filters.get("group_by"): |
| 47 | sel_col = '' |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 48 | ind = conditions["columns"].index(conditions["grbc"][0]) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 49 | |
| 50 | if filters.get("group_by") == 'Item': |
| 51 | sel_col = 't2.item_code' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 52 | elif filters.get("group_by") == 'Customer': |
| 53 | sel_col = 't1.customer' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 54 | elif filters.get("group_by") == 'Supplier': |
| 55 | sel_col = 't1.supplier' |
| 56 | |
| 57 | if filters.get('based_on') in ['Item','Customer','Supplier']: |
| 58 | inc = 2 |
| 59 | else : |
| 60 | inc = 1 |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 61 | data1 = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s |
Saurabh | 36cb3ca | 2013-06-21 16:25:28 +0530 | [diff] [blame] | 62 | where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and |
| 63 | t1.docstatus = 1 %s |
Saurabh | 5b6d03e | 2013-06-19 12:34:22 +0530 | [diff] [blame] | 64 | group by %s |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 65 | """ % (query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 66 | "%s", cond, conditions["group_by"]), (filters.get("company"), |
| 67 | filters["fiscal_year"]),as_list=1) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 68 | |
| 69 | for d in range(len(data1)): |
| 70 | #to add blanck column |
| 71 | dt = data1[d] |
| 72 | dt.insert(ind,'') |
| 73 | data.append(dt) |
| 74 | |
| 75 | #to get distinct value of col specified by group_by in filter |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 76 | row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s |
Saurabh | 5b6d03e | 2013-06-19 12:34:22 +0530 | [diff] [blame] | 77 | where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s |
| 78 | and t1.docstatus = 1 and %s = %s |
Nabin Hait | 4555d3b | 2013-06-21 16:27:34 +0530 | [diff] [blame] | 79 | """ % |
| 80 | (sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"], |
| 81 | "%s", "%s", conditions["group_by"], "%s"), |
| 82 | (filters.get("company"), filters.get("fiscal_year"), data1[d][0]), as_list=1) |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 83 | |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 84 | for i in range(len(row)): |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 85 | des = ['' for q in range(len(conditions["columns"]))] |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 86 | |
Saurabh | af5df66 | 2013-06-20 15:00:53 +0530 | [diff] [blame] | 87 | #get data for group_by filter |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 88 | row1 = webnotes.conn.sql(""" select %s , %s from `tab%s` t1, `tab%s Item` t2 %s |
Saurabh | 5b6d03e | 2013-06-19 12:34:22 +0530 | [diff] [blame] | 89 | where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s |
| 90 | and t1.docstatus = 1 and %s = %s and %s = %s |
Nabin Hait | 4555d3b | 2013-06-21 16:27:34 +0530 | [diff] [blame] | 91 | """ % |
| 92 | (sel_col, conditions["period_wise_select"], conditions["trans"], |
| 93 | conditions["trans"], conditions["addl_tables"], "%s", "%s", sel_col, |
| 94 | "%s", conditions["group_by"], "%s"), |
| 95 | (filters.get("company"), filters.get("fiscal_year"), row[i][0], |
| 96 | data1[d][0]), as_list=1) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 97 | |
| 98 | des[ind] = row[i] |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 99 | for j in range(1,len(conditions["columns"])-inc): |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 100 | des[j+inc] = row1[0][j] |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 101 | |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 102 | data.append(des) |
| 103 | else: |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 104 | data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s |
Saurabh | 36cb3ca | 2013-06-21 16:25:28 +0530 | [diff] [blame] | 105 | where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and |
| 106 | t1.docstatus = 1 %s |
Saurabh | 5b6d03e | 2013-06-19 12:34:22 +0530 | [diff] [blame] | 107 | group by %s |
Nabin Hait | 4555d3b | 2013-06-21 16:27:34 +0530 | [diff] [blame] | 108 | """ % |
| 109 | (query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], |
| 110 | "%s", "%s", cond,conditions["group_by"]), |
| 111 | (filters.get("company"), filters.get("fiscal_year")), as_list=1) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 112 | |
| 113 | return data |
| 114 | |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 115 | def get_mon(dt): |
| 116 | return getdate(dt).strftime("%b") |
Saurabh | d4f2199 | 2013-06-19 14:44:44 +0530 | [diff] [blame] | 117 | |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 118 | def period_wise_colums_query(filters, trans): |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 119 | query_details = '' |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 120 | pwc = [] |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 121 | bet_dates = get_period_date_ranges(filters.get("period"), filters.get("fiscal_year")) |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 122 | |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 123 | if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']: |
| 124 | trans_date = 'posting_date' |
| 125 | else: |
| 126 | trans_date = 'transaction_date' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 127 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 128 | if filters.get("period") != 'Yearly': |
| 129 | for dt in bet_dates: |
| 130 | get_period_wise_columns(dt, filters.get("period"), pwc) |
| 131 | query_details = get_period_wise_query(dt, trans_date, query_details) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 132 | else: |
Nabin Hait | 4555d3b | 2013-06-21 16:27:34 +0530 | [diff] [blame] | 133 | pwc = [filters.get("fiscal_year") + " (Qty):Float:120", |
| 134 | filters.get("fiscal_year") + " (Amt):Currency:120"] |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 135 | query_details = " SUM(t2.qty), SUM(t1.grand_total)," |
| 136 | |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 137 | query_details += 'SUM(t2.qty), SUM(t1.grand_total)' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 138 | return pwc, query_details |
| 139 | |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 140 | def get_period_wise_columns(bet_dates, period, pwc): |
| 141 | if period == 'Monthly': |
| 142 | pwc += [get_mon(bet_dates[0]) + " (Qty):Float:120", |
| 143 | get_mon(bet_dates[0]) + " (Amt):Currency:120"] |
| 144 | else: |
| 145 | pwc += [get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Qty):Float:120", |
| 146 | get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Amt):Currency:120"] |
| 147 | |
| 148 | def get_period_wise_query(bet_dates, trans_date, query_details): |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 149 | query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)), |
| 150 | SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)), |
Nabin Hait | 4555d3b | 2013-06-21 16:27:34 +0530 | [diff] [blame] | 151 | """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 152 | return query_details |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 153 | |
Akhilesh Darjee | ec0da0b | 2013-11-25 19:51:18 +0530 | [diff] [blame] | 154 | @webnotes.whitelist(allow_guest=True) |
| 155 | def get_period_date_ranges(period, fiscal_year=None, year_start_date=None): |
| 156 | from dateutil.relativedelta import relativedelta |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 157 | |
Akhilesh Darjee | ec0da0b | 2013-11-25 19:51:18 +0530 | [diff] [blame] | 158 | if not year_start_date: |
| 159 | year_start_date, year_end_date = webnotes.conn.get_value("Fiscal Year", |
| 160 | fiscal_year, ["year_start_date", "year_end_date"]) |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 161 | |
Akhilesh Darjee | ec0da0b | 2013-11-25 19:51:18 +0530 | [diff] [blame] | 162 | increment = { |
| 163 | "Monthly": 1, |
| 164 | "Quarterly": 3, |
| 165 | "Half-Yearly": 6, |
| 166 | "Yearly": 12 |
| 167 | }.get(period) |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 168 | |
Akhilesh Darjee | ec0da0b | 2013-11-25 19:51:18 +0530 | [diff] [blame] | 169 | period_date_ranges = [] |
| 170 | for i in xrange(1, 13, increment): |
| 171 | period_end_date = getdate(year_start_date) + relativedelta(months=increment, days=-1) |
| 172 | if period_end_date > getdate(year_end_date): |
| 173 | period_end_date = year_end_date |
| 174 | period_date_ranges.append([year_start_date, period_end_date]) |
| 175 | year_start_date = period_end_date + relativedelta(days=1) |
| 176 | if period_end_date == year_end_date: |
| 177 | break |
| 178 | |
| 179 | return period_date_ranges |
Saurabh | f8f68c5 | 2013-06-20 18:52:31 +0530 | [diff] [blame] | 180 | |
| 181 | def get_period_month_ranges(period, fiscal_year): |
| 182 | from dateutil.relativedelta import relativedelta |
| 183 | period_month_ranges = [] |
| 184 | |
| 185 | for start_date, end_date in get_period_date_ranges(period, fiscal_year): |
| 186 | months_in_this_period = [] |
| 187 | while start_date <= end_date: |
| 188 | months_in_this_period.append(start_date.strftime("%B")) |
| 189 | start_date += relativedelta(months=1) |
| 190 | period_month_ranges.append(months_in_this_period) |
| 191 | |
| 192 | return period_month_ranges |
| 193 | |
| 194 | def based_wise_colums_query(based_on, trans): |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 195 | based_on_details = {} |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 196 | |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 197 | # based_on_cols, based_on_select, based_on_group_by, addl_tables |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 198 | if based_on == "Item": |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 199 | based_on_details["based_on_cols"] = ["Item:Link/Item:120", "Item Name:Data:120"] |
| 200 | based_on_details["based_on_select"] = "t2.item_code, t2.item_name," |
| 201 | based_on_details["based_on_group_by"] = 't2.item_code' |
| 202 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 203 | |
| 204 | elif based_on == "Item Group": |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 205 | based_on_details["based_on_cols"] = ["Item Group:Link/Item Group:120"] |
| 206 | based_on_details["based_on_select"] = "t2.item_group," |
| 207 | based_on_details["based_on_group_by"] = 't2.item_group' |
| 208 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 209 | |
| 210 | elif based_on == "Customer": |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 211 | based_on_details["based_on_cols"] = ["Customer:Link/Customer:120", "Territory:Link/Territory:120"] |
| 212 | based_on_details["based_on_select"] = "t1.customer_name, t1.territory, " |
| 213 | based_on_details["based_on_group_by"] = 't1.customer_name' |
| 214 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 215 | |
| 216 | elif based_on == "Customer Group": |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 217 | based_on_details["based_on_cols"] = ["Customer Group:Link/Customer Group"] |
| 218 | based_on_details["based_on_select"] = "t1.customer_group," |
| 219 | based_on_details["based_on_group_by"] = 't1.customer_group' |
| 220 | based_on_details["addl_tables"] = '' |
| 221 | |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 222 | elif based_on == 'Supplier': |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 223 | based_on_details["based_on_cols"] = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:140"] |
| 224 | based_on_details["based_on_select"] = "t1.supplier, t3.supplier_type," |
| 225 | based_on_details["based_on_group_by"] = 't1.supplier' |
| 226 | based_on_details["addl_tables"] = ',`tabSupplier` t3' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 227 | |
| 228 | elif based_on == 'Supplier Type': |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 229 | based_on_details["based_on_cols"] = ["Supplier Type:Link/Supplier Type:140"] |
| 230 | based_on_details["based_on_select"] = "t3.supplier_type," |
| 231 | based_on_details["based_on_group_by"] = 't3.supplier_type' |
| 232 | based_on_details["addl_tables"] =',`tabSupplier` t3' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 233 | |
| 234 | elif based_on == "Territory": |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 235 | based_on_details["based_on_cols"] = ["Territory:Link/Territory:120"] |
| 236 | based_on_details["based_on_select"] = "t1.territory," |
| 237 | based_on_details["based_on_group_by"] = 't1.territory' |
| 238 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 239 | |
| 240 | elif based_on == "Project": |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 241 | if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']: |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 242 | based_on_details["based_on_cols"] = ["Project:Link/Project:120"] |
| 243 | based_on_details["based_on_select"] = "t1.project_name," |
| 244 | based_on_details["based_on_group_by"] = 't1.project_name' |
| 245 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 246 | elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']: |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 247 | based_on_details["based_on_cols"] = ["Project:Link/Project:120"] |
| 248 | based_on_details["based_on_select"] = "t2.project_name," |
| 249 | based_on_details["based_on_group_by"] = 't2.project_name' |
| 250 | based_on_details["addl_tables"] = '' |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 251 | else: |
Nabin Hait | b8ebbca | 2013-06-20 13:03:10 +0530 | [diff] [blame] | 252 | webnotes.msgprint("Project-wise data is not available for Quotation", raise_exception=1) |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 253 | |
Saurabh | 2b02f14 | 2013-06-21 10:46:26 +0530 | [diff] [blame] | 254 | return based_on_details |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 255 | |
Saurabh | 1848b71 | 2013-06-14 15:03:45 +0530 | [diff] [blame] | 256 | def group_wise_column(group_by): |
Saurabh | 0326f54 | 2013-06-13 19:17:56 +0530 | [diff] [blame] | 257 | if group_by: |
| 258 | return [group_by+":Link/"+group_by+":120"] |
| 259 | else: |
| 260 | return [] |