From b8ebbcafa997de794ac296d4130e26f8207c59ff Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 20 Jun 2013 13:03:10 +0530 Subject: [PATCH 1/5] [trend analyzer] cleanup --- controllers/trends.py | 105 ++++++++-------- .../quotation_trends/quotation_trends.py | 5 +- stock/doctype/serial_no/serial_no.txt | 116 ++++++++---------- 3 files changed, 100 insertions(+), 126 deletions(-) diff --git a/controllers/trends.py b/controllers/trends.py index 4edb7845ceb..c0636cba459 100644 --- a/controllers/trends.py +++ b/controllers/trends.py @@ -16,33 +16,39 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cint, add_days, add_months, cstr -from datetime import datetime +from webnotes.utils import add_days, add_months, cstr, getdate +from webnotes import _ def get_columns(filters, trans): + validate_filters(filters) + + # based_on_cols, based_on_select, based_on_group_by, addl_tables + bonc, query_bon, based, sup_tab = basedon_wise_colums_query(filters.get("based_on"), trans) + # period_cols, period_select + pwc, query_pwc = period_wise_colums_query(filters, trans) + + # group_by_cols + grbc = group_wise_column(filters.get("group_by")) - if not (filters.get("period") and filters.get("based_on")): - webnotes.msgprint("Value missing in 'Period' or 'Based On'", raise_exception=1) + columns = bonc + pwc + ["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"] + if grbc: + columns = bonc + grbc + pwc +["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"] - elif filters.get("based_on") == filters.get("group_by"): - webnotes.msgprint("Plese select different values in 'Based On' and 'Group By'", raise_exception=1) - - else: - bonc, query_bon, based, sup_tab = basedon_wise_colums_query(filters.get("based_on"), trans) - pwc, query_pwc = period_wise_colums_query(filters, trans) - grbc = group_wise_column(filters.get("group_by")) - - columns = bonc + pwc + ["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"] - if grbc: - columns = bonc + grbc + pwc +["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"] - - details = {"query_bon": query_bon, "query_pwc": query_pwc, "columns": columns, "basedon": based, - "grbc": grbc, "sup_tab": sup_tab} + # conditions + details = {"query_bon": query_bon, "query_pwc": query_pwc, "columns": columns, + "basedon": based, "grbc": grbc, "sup_tab": sup_tab} return details -def get_data(filters, tab, details): +def validate_filters(filters): + for f in ["Fiscal Year", "Based On", "Period", "Company"]: + if not filters.get(f.lower().replace(" ", "_")): + webnotes.msgprint(f + _(" is mandatory"), raise_exception=1) + if filters.get("based_on") == filters.get("group_by"): + webnotes.msgprint("'Based On' and 'Group By' can not be same", raise_exception=1) + +def get_data(filters, tab, details): data = [] inc, cond= '','' query_details = details["query_bon"] + details["query_pwc"] @@ -96,17 +102,17 @@ def get_data(filters, tab, details): 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 - """%(sel_col, details["query_pwc"], tab[0], tab[1], details["sup_tab"], + """ % (sel_col, details["query_pwc"], tab[0], tab[1], details["sup_tab"], "%s", "%s", sel_col, "%s", details["basedon"], "%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] for j in range(1,len(details["columns"])-inc): des[j+inc] = row1[0][j] + data.append(des) else: - data = webnotes.conn.sql(""" select %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 %s @@ -118,20 +124,13 @@ def get_data(filters, tab, details): return data -def get_mon(date): - """convert srting formated date into date and retrieve month abbrevation""" - return (datetime.strptime(date, '%Y-%m-%d')).strftime("%b") +def get_mon(dt): + return getdate(dt).strftime("%b") def period_wise_colums_query(filters, trans): - from datetime import datetime - query_details = '' pwc = [] - ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` where name = '%s' - """%filters.get("fiscal_year"))[0][0] - - year_start_date = ysd.strftime('%Y-%m-%d') - start_month = cint(year_start_date.split('-')[1]) + ysd = webnotes.conn.get_value("Fiscal year", filters.get("fiscal_year"), "year_start_date") if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']: trans_date = 'posting_date' @@ -141,27 +140,13 @@ def period_wise_colums_query(filters, trans): if filters.get("period") == "Monthly": month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] - for month in range(start_month-1,len(month_name)): - pwc.append(month_name[month]+' (Qty):Float:120') - pwc.append(month_name[month]+' (Amt):Currency:120') - - query_details += """ - Sum(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t2.qty, NULL)), - SUM(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t1.grand_total, NULL)), - """%{"trans": trans_date,"mon_num": cstr(month+1)} - - for month in range(0, start_month-1): - pwc.append(month_name[month]+' (Qty):Float:120') - pwc.append(month_name[month]+' (Amt):Currency:120') - - query_details += """ - Sum(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t2.qty, NULL)), - SUM(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t1.grand_total, NULL)), - """%{"trans": trans_date, "mon_num": cstr(month+1)} + for month_idx in range(ysd.month-1,len(month_name)) + range(0, ysd.month-1): + query_details = get_monthly_conditions(month_name, month_idx, trans_date, + pwc, query_details) 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_qsd, second_qsd, third_qsd, fourth_qsd = ysd, add_months(ysd,3), add_months(ysd,6), add_months(ysd,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) bet_dates = [[first_qsd,first_qed],[second_qsd,second_qed],[third_qsd,third_qed],[fourth_qsd,fourth_qed]] @@ -178,7 +163,7 @@ def period_wise_colums_query(filters, trans): elif filters.get("period") == "Half-yearly": - first_half_start = year_start_date + first_half_start = ysd first_half_end = add_days(add_months(first_half_start,6),-1) second_half_start = add_days(first_half_end,1) second_half_end = add_days(add_months(second_half_start,6),-1) @@ -200,6 +185,17 @@ def period_wise_colums_query(filters, trans): query_details += 'SUM(t2.qty), SUM(t1.grand_total)' return pwc, query_details + +def get_monthly_conditions(month_list, month_idx, trans_date, pwc, query_details): + pwc += [month_list[month_idx] + ' (Qty):Float:120', + month_list[month_idx] + ' (Amt):Currency:120'] + + query_details += """ + Sum(IF(MONTH(t1.%(trans_date)s)= %(mon_num)s, t2.qty, NULL)), + SUM(IF(MONTH(t1.%(trans_date)s)= %(mon_num)s, t1.grand_total, NULL)), + """ % {"trans_date": trans_date, "mon_num": cstr(month_idx+1)} + + return query_details def basedon_wise_colums_query(based_on, trans): sup_tab = '' @@ -242,19 +238,16 @@ def basedon_wise_colums_query(based_on, trans): based = 't1.territory' 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' - elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']: bon = ["Project:Link/Project:120"] query_details = "t2.project_name," based = 't2.project_name' - else: - webnotes.msgprint("Information Not Available", raise_exception=1) + webnotes.msgprint("Project-wise data is not available for Quotation", raise_exception=1) return bon, query_details, based, sup_tab diff --git a/selling/report/quotation_trends/quotation_trends.py b/selling/report/quotation_trends/quotation_trends.py index e341752cd01..c6a54c75886 100644 --- a/selling/report/quotation_trends/quotation_trends.py +++ b/selling/report/quotation_trends/quotation_trends.py @@ -16,7 +16,7 @@ from __future__ import unicode_literals import webnotes -from controllers.trends import get_columns,get_data +from controllers.trends import get_columns, get_data def execute(filters=None): if not filters: filters ={} @@ -27,8 +27,5 @@ def execute(filters=None): details = get_columns(filters, trans) data = get_data(filters, tab, details) - - if not data: - webnotes.msgprint("Data not found for selected criterias") return details["columns"], data \ No newline at end of file diff --git a/stock/doctype/serial_no/serial_no.txt b/stock/doctype/serial_no/serial_no.txt index 8e891b81724..33160c785fe 100644 --- a/stock/doctype/serial_no/serial_no.txt +++ b/stock/doctype/serial_no/serial_no.txt @@ -1,14 +1,14 @@ [ { - "creation": "2013-01-29 19:25:41", + "creation": "2013-05-16 10:59:15", "docstatus": 0, - "modified": "2013-01-29 16:27:57", + "modified": "2013-06-20 11:23:01", "modified_by": "Administrator", "owner": "Administrator" }, { "allow_attach": 1, - "allow_rename": 1, + "allow_rename": 0, "autoname": "field:serial_no", "description": "Distinct unit of an Item", "doctype": "DocType", @@ -31,7 +31,9 @@ "parent": "Serial No", "parentfield": "permissions", "parenttype": "DocType", + "permlevel": 0, "read": 1, + "report": 1, "submit": 0 }, { @@ -43,12 +45,14 @@ "fieldname": "details", "fieldtype": "Section Break", "label": "Details", - "oldfieldtype": "Section Break" + "oldfieldtype": "Section Break", + "read_only": 0 }, { "doctype": "DocField", "fieldname": "column_break0", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "read_only": 0 }, { "default": "In Store", @@ -75,6 +79,7 @@ "no_copy": 1, "oldfieldname": "serial_no", "oldfieldtype": "Data", + "read_only": 0, "reqd": 1, "search_index": 1 }, @@ -88,13 +93,15 @@ "oldfieldname": "item_code", "oldfieldtype": "Link", "options": "Item", + "read_only": 0, "reqd": 1, "search_index": 0 }, { "doctype": "DocField", "fieldname": "column_break1", - "fieldtype": "Column Break" + "fieldtype": "Column Break", + "read_only": 0 }, { "doctype": "DocField", @@ -146,12 +153,14 @@ "doctype": "DocField", "fieldname": "purchase_details", "fieldtype": "Section Break", - "label": "Purchase Details" + "label": "Purchase Details", + "read_only": 0 }, { "doctype": "DocField", "fieldname": "column_break2", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -160,7 +169,8 @@ "fieldtype": "Select", "label": "Purchase Document Type", "no_copy": 1, - "options": "\nPurchase Receipt\nStock Entry" + "options": "\nPurchase Receipt\nStock Entry", + "read_only": 0 }, { "doctype": "DocField", @@ -168,7 +178,8 @@ "fieldtype": "Data", "hidden": 0, "label": "Purchase Document No", - "no_copy": 1 + "no_copy": 1, + "read_only": 0 }, { "doctype": "DocField", @@ -179,6 +190,7 @@ "no_copy": 1, "oldfieldname": "purchase_date", "oldfieldtype": "Date", + "read_only": 0, "reqd": 0, "search_index": 0 }, @@ -188,6 +200,7 @@ "fieldtype": "Time", "label": "Incoming Time", "no_copy": 1, + "read_only": 0, "reqd": 1 }, { @@ -200,6 +213,7 @@ "oldfieldname": "purchase_rate", "oldfieldtype": "Currency", "options": "Company:company:default_currency", + "read_only": 0, "reqd": 1, "search_index": 0 }, @@ -207,6 +221,7 @@ "doctype": "DocField", "fieldname": "column_break3", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -220,6 +235,7 @@ "oldfieldname": "warehouse", "oldfieldtype": "Link", "options": "Warehouse", + "read_only": 0, "reqd": 0, "search_index": 1 }, @@ -230,7 +246,8 @@ "in_filter": 1, "label": "Supplier", "no_copy": 1, - "options": "Supplier" + "options": "Supplier", + "read_only": 0 }, { "doctype": "DocField", @@ -254,12 +271,14 @@ "fieldname": "delivery_details", "fieldtype": "Section Break", "label": "Delivery Details", - "oldfieldtype": "Column Break" + "oldfieldtype": "Column Break", + "read_only": 0 }, { "doctype": "DocField", "fieldname": "column_break4", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -318,12 +337,14 @@ "oldfieldname": "is_cancelled", "oldfieldtype": "Select", "options": "\nYes\nNo", + "read_only": 0, "report_hide": 1 }, { "doctype": "DocField", "fieldname": "column_break5", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -378,12 +399,14 @@ "doctype": "DocField", "fieldname": "warranty_amc_details", "fieldtype": "Section Break", - "label": "Warranty / AMC Details" + "label": "Warranty / AMC Details", + "read_only": 0 }, { "doctype": "DocField", "fieldname": "column_break6", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -396,6 +419,7 @@ "oldfieldname": "maintenance_status", "oldfieldtype": "Select", "options": "\nUnder Warranty\nOut of Warranty\nUnder AMC\nOut of AMC", + "read_only": 0, "search_index": 1, "width": "150px" }, @@ -406,12 +430,14 @@ "label": "Warranty Period (Days)", "oldfieldname": "warranty_period", "oldfieldtype": "Int", + "read_only": 0, "width": "150px" }, { "doctype": "DocField", "fieldname": "column_break7", "fieldtype": "Column Break", + "read_only": 0, "width": "50%" }, { @@ -422,6 +448,7 @@ "label": "Warranty Expiry Date", "oldfieldname": "warranty_expiry_date", "oldfieldtype": "Date", + "read_only": 0, "width": "150px" }, { @@ -432,6 +459,7 @@ "label": "AMC Expiry Date", "oldfieldname": "amc_expiry_date", "oldfieldtype": "Date", + "read_only": 0, "search_index": 0, "width": "150px" }, @@ -439,13 +467,15 @@ "doctype": "DocField", "fieldname": "more_info", "fieldtype": "Section Break", - "label": "More Info" + "label": "More Info", + "read_only": 0 }, { "doctype": "DocField", "fieldname": "serial_no_details", "fieldtype": "Text Editor", - "label": "Serial No Details" + "label": "Serial No Details", + "read_only": 0 }, { "doctype": "DocField", @@ -454,6 +484,7 @@ "in_filter": 1, "label": "Company", "options": "link:Company", + "read_only": 0, "reqd": 1, "search_index": 1 }, @@ -464,6 +495,7 @@ "in_filter": 1, "label": "Fiscal Year", "options": "link:Fiscal Year", + "read_only": 0, "reqd": 1, "search_index": 1 }, @@ -487,54 +519,10 @@ "read_only": 1, "report_hide": 1 }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "match": "", - "permlevel": 1, - "report": 0, - "role": "Material Manager", - "write": 0 - }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "permlevel": 0, - "report": 1, - "role": "Material Manager", - "write": 0 - }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "match": "", - "permlevel": 1, - "report": 0, - "role": "Material User", - "write": 0 - }, - { - "amend": 0, - "cancel": 0, - "create": 0, - "doctype": "DocPerm", - "permlevel": 0, - "report": 1, - "role": "Material User", - "write": 0 - }, { "cancel": 1, "create": 1, "doctype": "DocPerm", - "permlevel": 0, - "report": 1, "role": "System Manager", "write": 1 }, @@ -542,8 +530,6 @@ "cancel": 1, "create": 1, "doctype": "DocPerm", - "permlevel": 0, - "report": 1, "role": "Material Master Manager", "write": 1 }, @@ -552,17 +538,15 @@ "cancel": 0, "create": 0, "doctype": "DocPerm", - "match": "", - "permlevel": 1, - "role": "System Manager" + "role": "Material Manager", + "write": 0 }, { "amend": 0, "cancel": 0, "create": 0, "doctype": "DocPerm", - "match": "", - "permlevel": 1, - "role": "Sales Master Manager" + "role": "Material User", + "write": 0 } ] \ No newline at end of file From 0930b94264bc09adc3fd269e1ae083991f263e82 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 20 Jun 2013 16:35:09 +0530 Subject: [PATCH 2/5] [target report] cleanup --- accounts/utils.py | 16 +++++--- ...itory_target_variance_(item_group_wise).py | 37 +++++++------------ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/accounts/utils.py b/accounts/utils.py index eb240e796c0..fa93cb06286 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -26,17 +26,23 @@ from utilities import build_filter_conditions class FiscalYearError(webnotes.ValidationError): pass -def get_fiscal_year(date, verbose=1): - return get_fiscal_years(date, verbose=1)[0] +def get_fiscal_year(date=None, fiscal_year=None, verbose=1): + return get_fiscal_years(date, fiscal_year, verbose=1)[0] -def get_fiscal_years(date, verbose=1): +def get_fiscal_years(date=None, fiscal_year=None, verbose=1): # if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate) + cond = "" + if fiscal_year: + cond = "name = '%s'" % fiscal_year + else: + cond = "'%s' >= year_start_date and '%s' < adddate(year_start_date, interval 1 year)" % \ + (date, date) fy = webnotes.conn.sql("""select name, year_start_date, subdate(adddate(year_start_date, interval 1 year), interval 1 day) as year_end_date from `tabFiscal Year` - where %s >= year_start_date and %s < adddate(year_start_date, interval 1 year) - order by year_start_date desc""", (date, date)) + where %s + order by year_start_date desc""" % cond) if not fy: error_msg = """%s not in any Fiscal Year""" % formatdate(date) diff --git a/selling/report/territory_target_variance_(item_group_wise)/territory_target_variance_(item_group_wise).py b/selling/report/territory_target_variance_(item_group_wise)/territory_target_variance_(item_group_wise).py index 079f8e82a2a..022d19ecf64 100644 --- a/selling/report/territory_target_variance_(item_group_wise)/territory_target_variance_(item_group_wise).py +++ b/selling/report/territory_target_variance_(item_group_wise)/territory_target_variance_(item_group_wise).py @@ -20,6 +20,7 @@ import calendar from webnotes import _, msgprint from webnotes.utils import flt import time +from accounts.utils import get_fiscal_year def execute(filters=None): if not filters: filters = {} @@ -54,8 +55,7 @@ def get_columns(filters): for fieldname in ["fiscal_year", "period", "target_on"]: if not filters.get(fieldname): label = (" ".join(fieldname.split("_"))).title() - msgprint(_("Please specify") + ": " + label, - raise_exception=True) + msgprint(_("Please specify") + ": " + label, raise_exception=True) columns = ["Territory:Link/Territory:80", "Item Group:Link/Item Group:80"] @@ -72,8 +72,8 @@ def get_columns(filters): def get_period_date_ranges(filters): from dateutil.relativedelta import relativedelta - - year_start_date, year_end_date = get_year_start_end_date(filters) + year_start_date, year_end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] + increment = { "Monthly": 1, @@ -111,8 +111,8 @@ def get_territory_details(filters): td.target_amount, t.distribution_id from `tabTerritory` t, `tabTarget Detail` td where td.parent=t.name and td.fiscal_year=%s and - ifnull(t.distribution_id, '')!='' order by t.name""" % - ('%s'), (filters.get("fiscal_year")), as_dict=1) + ifnull(t.distribution_id, '')!='' order by t.name""", + filters.get("fiscal_year"), as_dict=1) #Get target distribution details of item group def get_target_distribution_details(filters): @@ -128,7 +128,7 @@ def get_target_distribution_details(filters): #Get achieved details from sales order def get_achieved_details(filters): - start_date, end_date = get_year_start_end_date(filters) + start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] return webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, so.territory, MONTHNAME(so.transaction_date) as month_name @@ -148,35 +148,26 @@ def get_territory_item_month_map(filters): for month in tdd: tim_map.setdefault(td.name, {}).setdefault(td.item_group, {})\ .setdefault(month, webnotes._dict({ - "target": 0.0, "achieved": 0.0, "variance": 0.0 + "target": 0.0, "achieved": 0.0 })) tav_dict = tim_map[td.name][td.item_group][month] for ad in achieved_details: if (filters["target_on"] == "Quantity"): - tav_dict.target = td.target_qty*(tdd[month]["percentage_allocation"]/100) - if ad.month_name == month and ''.join(get_item_group(ad.item_code)) == td.item_group \ + tav_dict.target = flt(td.target_qty) * (tdd[month]["percentage_allocation"]/100) + if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \ and ad.territory == td.name: tav_dict.achieved += ad.qty if (filters["target_on"] == "Amount"): - tav_dict.target = td.target_amount*(tdd[month]["percentage_allocation"]/100) - if ad.month_name == month and ''.join(get_item_group(ad.item_code)) == td.item_group \ + tav_dict.target = flt(td.target_amount) * \ + (tdd[month]["percentage_allocation"]/100) + if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \ and ad.territory == td.name: tav_dict.achieved += ad.amount return tim_map -def get_year_start_end_date(filters): - return webnotes.conn.sql("""select year_start_date, - subdate(adddate(year_start_date, interval 1 year), interval 1 day) - as year_end_date - from `tabFiscal Year` - where name=%s""", filters["fiscal_year"])[0] - def get_item_group(item_name): - """Get Item Group of an item""" - - return webnotes.conn.sql_list("select item_group from `tabItem` where name=%s""" % - ('%s'), (item_name)) \ No newline at end of file + return webnotes.conn.get_value("Item", item_name, "item_group") \ No newline at end of file From b7784eac365876dff9c93f95b6b761dd8826a99c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 20 Jun 2013 17:19:51 +0530 Subject: [PATCH 3/5] [fix][report] in item prices --- stock/report/item_prices/item_prices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py index 86ae085ce70..c8d0b69db5f 100644 --- a/stock/report/item_prices/item_prices.py +++ b/stock/report/item_prices/item_prices.py @@ -101,7 +101,7 @@ def get_valuation_rate(): val_rate_map = {} for d in webnotes.conn.sql("""select item_code, avg(valuation_rate) as val_rate - from tabBin group by item_code""", as_dict=1): + from tabBin where actual_qty > 0 group by item_code""", as_dict=1): val_rate_map.setdefault(d.item_code, d.val_rate) return val_rate_map \ No newline at end of file From 71253bea0f4bd055605aa88363233c78702abca5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 20 Jun 2013 17:32:00 +0530 Subject: [PATCH 4/5] [fix][report] in item prices --- stock/report/item_prices/item_prices.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py index c8d0b69db5f..3bdb7465105 100644 --- a/stock/report/item_prices/item_prices.py +++ b/stock/report/item_prices/item_prices.py @@ -100,7 +100,8 @@ def get_valuation_rate(): val_rate_map = {} - for d in webnotes.conn.sql("""select item_code, avg(valuation_rate) as val_rate + for d in webnotes.conn.sql("""select item_code, + sum(actual_qty*valuation_rate)/sum(actual_qty) as val_rate from tabBin where actual_qty > 0 group by item_code""", as_dict=1): val_rate_map.setdefault(d.item_code, d.val_rate) From 8df49ca772c046f9d4e091bba36096bb1ec43512 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 21 Jun 2013 12:05:35 +0530 Subject: [PATCH 5/5] [buying] [fix] on change of currency, set conversion rate = 1 if currency=company currency --- buying/doctype/purchase_common/purchase_common.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index dacee80e55d..9e291f5f178 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -128,23 +128,27 @@ erpnext.buying.BuyingController = wn.ui.form.Controller.extend({ }, currency: function() { - this.set_dynamic_labels(); + if(this.frm.doc.currency === this.get_company_currency()) + this.frm.set_value("conversion_rate", 1.0); + + this.price_list_currency(); }, company: function() { - this.set_dynamic_labels(); + if(this.frm.fields_dict.currency) + this.set_dynamic_labels(); }, price_list_currency: function() { this.frm.toggle_reqd("plc_conversion_rate", !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); - this.set_dynamic_labels(); - if(this.frm.doc.price_list_currency === this.get_company_currency()) this.frm.set_value("plc_conversion_rate", 1.0); else if(this.frm.doc.price_list_currency === this.frm.doc.currency) this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0); + + this.set_dynamic_labels(); }, set_dynamic_labels: function(doc, dt, dn) {