From bfe264be8c4ce1c9f42a45f8b3d9f104396cab5d Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 13 Nov 2013 16:45:11 +0530 Subject: [PATCH 1/3] [fix] [minor] all types of variance reports fixed --- .../budget_variance_report.py | 3 --- ..._person_target_variance_item_group_wise.py | 18 +++++++++---- ...rritory_target_variance_item_group_wise.py | 26 ++++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/accounts/report/budget_variance_report/budget_variance_report.py b/accounts/report/budget_variance_report/budget_variance_report.py index c1c4bc1ae8..f4665ece6b 100644 --- a/accounts/report/budget_variance_report/budget_variance_report.py +++ b/accounts/report/budget_variance_report/budget_variance_report.py @@ -16,10 +16,7 @@ def execute(filters=None): period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"]) cam_map = get_costcenter_account_month_map(filters) - precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2 - data = [] - for cost_center, cost_center_items in cam_map.items(): for account, monthwise_data in cost_center_items.items(): row = [cost_center, account] diff --git a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py index 6fdafe083d..d2220f4cd7 100644 --- a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py +++ b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py @@ -58,7 +58,8 @@ def get_columns(filters): columns.append(label+":Float:120") - return columns + ["Total Target::120", "Total Achieved::120", "Total Variance::120"] + return columns + ["Total Target:Float:120", "Total Achieved:Float:120", + "Total Variance:Float:120"] #Get sales person & item group details def get_salesperson_details(filters): @@ -83,7 +84,7 @@ def get_target_distribution_details(filters): def get_achieved_details(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, + item_details = webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, st.sales_person, MONTHNAME(so.transaction_date) as month_name from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st where soi.parent=so.name and so.docstatus=1 and @@ -91,6 +92,13 @@ def get_achieved_details(filters): so.transaction_date<=%s""" % ('%s', '%s'), (start_date, end_date), as_dict=1) + item_actual_details = {} + for d in item_details: + item_actual_details.setdefault(d.sales_person, {}).setdefault(\ + get_item_group(d.item_code), []).append(d) + + return item_actual_details + def get_salesperson_item_month_map(filters): import datetime salesperson_details = get_salesperson_details(filters) @@ -110,15 +118,15 @@ def get_salesperson_item_month_map(filters): month_percentage = sd.distribution_id and \ tdd.get(sd.distribution_id, {}).get(month, 0) or 100.0/12 - for ad in achieved_details: + for ad in achieved_details.get(sd.name, {}).get(sd.item_group, []): if (filters["target_on"] == "Quantity"): - tav_dict.target = flt(flt(sd.target_qty) * month_percentage/100, 2) + tav_dict.target = flt(sd.target_qty) * month_percentage / 100 if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \ and ad.sales_person == sd.name: tav_dict.achieved += ad.qty if (filters["target_on"] == "Amount"): - tav_dict.target = flt(flt(sd.target_amount) * month_percentage/100, 2) + tav_dict.target = flt(sd.target_amount) * month_percentage / 100 if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \ and ad.sales_person == sd.name: tav_dict.achieved += ad.amount 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 829f7818e3..72657f0dba 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 @@ -15,11 +15,8 @@ def execute(filters=None): columns = get_columns(filters) period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"]) tim_map = get_territory_item_month_map(filters) - - precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2 - + data = [] - for territory, territory_items in tim_map.items(): for item_group, monthwise_data in territory_items.items(): row = [territory, item_group] @@ -29,7 +26,7 @@ def execute(filters=None): for month in relevant_months: month_data = monthwise_data.get(month, {}) for i, fieldname in enumerate(["target", "achieved", "variance"]): - value = flt(month_data.get(fieldname), precision) + value = flt(month_data.get(fieldname)) period_data[i] += value totals[i] += value period_data[2] = period_data[0] - period_data[1] @@ -58,7 +55,8 @@ def get_columns(filters): label = label % from_date.strftime("%b") columns.append(label+":Float:120") - return columns + ["Total Target::120", "Total Achieved::120", "Total Variance::120"] + return columns + ["Total Target:Float:120", "Total Achieved:Float:120", + "Total Variance:Float:120"] #Get territory & item group details def get_territory_details(filters): @@ -83,14 +81,22 @@ def get_target_distribution_details(filters): def get_achieved_details(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, + item_details = webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, so.territory, MONTHNAME(so.transaction_date) as month_name from `tabSales Order Item` soi, `tabSales Order` so where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and so.transaction_date<=%s""" % ('%s', '%s'), (start_date, end_date), as_dict=1) + item_actual_details = {} + for d in item_details: + item_actual_details.setdefault(d.territory, {}).setdefault(\ + get_item_group(d.item_code), []).append(d) + + return item_actual_details + def get_territory_item_month_map(filters): + import datetime territory_details = get_territory_details(filters) tdd = get_target_distribution_details(filters) achieved_details = get_achieved_details(filters) @@ -110,15 +116,15 @@ def get_territory_item_month_map(filters): month_percentage = td.distribution_id and \ tdd.get(td.distribution_id, {}).get(month, 0) or 100.0/12 - for ad in achieved_details: + for ad in achieved_details.get(td.name, {}).get(td.item_group, []): if (filters["target_on"] == "Quantity"): - tav_dict.target = flt(flt(td.target_qty) * month_percentage /100) + tav_dict.target = flt(td.target_qty) * month_percentage / 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 = flt(flt(td.target_amount) * month_percentage / 100) + tav_dict.target = flt(td.target_amount) * month_percentage / 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 From d2d210dc686541a7b3a51c2eeb83e37b71d8fb27 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 13 Nov 2013 17:27:35 +0530 Subject: [PATCH 2/3] [fix] [minor] variance reports fixes --- .../report/budget_variance_report/budget_variance_report.py | 3 +-- .../sales_person_target_variance_item_group_wise.py | 6 ++---- .../territory_target_variance_item_group_wise.py | 6 ++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/accounts/report/budget_variance_report/budget_variance_report.py b/accounts/report/budget_variance_report/budget_variance_report.py index f4665ece6b..0e241dea1d 100644 --- a/accounts/report/budget_variance_report/budget_variance_report.py +++ b/accounts/report/budget_variance_report/budget_variance_report.py @@ -119,8 +119,7 @@ def get_costcenter_account_month_map(filters): tav_dict.target = flt(ccd.budget_allocated) * month_percentage /100 for ad in actual_details.get(ccd.name, {}).get(ccd.account, []): - if ad.month_name == month and ad.account == ccd.account \ - and ad.cost_center == ccd.name: + if ad.month_name == month: tav_dict.actual += ad.debit - ad.credit return cam_map \ No newline at end of file diff --git a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py index d2220f4cd7..ebb2d9f96f 100644 --- a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py +++ b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py @@ -121,14 +121,12 @@ def get_salesperson_item_month_map(filters): for ad in achieved_details.get(sd.name, {}).get(sd.item_group, []): if (filters["target_on"] == "Quantity"): tav_dict.target = flt(sd.target_qty) * month_percentage / 100 - if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \ - and ad.sales_person == sd.name: + if ad.month_name == month: tav_dict.achieved += ad.qty if (filters["target_on"] == "Amount"): tav_dict.target = flt(sd.target_amount) * month_percentage / 100 - if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \ - and ad.sales_person == sd.name: + if ad.month_name == month: tav_dict.achieved += ad.amount return sim_map 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 72657f0dba..2aafe3c6bd 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 @@ -119,14 +119,12 @@ def get_territory_item_month_map(filters): for ad in achieved_details.get(td.name, {}).get(td.item_group, []): if (filters["target_on"] == "Quantity"): tav_dict.target = flt(td.target_qty) * month_percentage / 100 - if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \ - and ad.territory == td.name: + if ad.month_name == month: tav_dict.achieved += ad.qty if (filters["target_on"] == "Amount"): tav_dict.target = flt(td.target_amount) * month_percentage / 100 - if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \ - and ad.territory == td.name: + if ad.month_name == month: tav_dict.achieved += ad.amount return tim_map From 65e974096f4969303081c76d0067fabae1f84269 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 14 Nov 2013 14:50:43 +0530 Subject: [PATCH 3/3] [fix] showing customer dashboard headline to users with account related roles --- buying/doctype/supplier/supplier.js | 21 ++++++++++----------- selling/doctype/customer/customer.js | 17 ++++++++++------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js index 75542c8257..58045f5aa9 100644 --- a/buying/doctype/supplier/supplier.js +++ b/buying/doctype/supplier/supplier.js @@ -3,10 +3,6 @@ wn.require('app/setup/doctype/contact_control/contact_control.js'); -cur_frm.cscript.onload = function(doc,dt,dn){ - -} - cur_frm.cscript.refresh = function(doc,dt,dn) { cur_frm.cscript.make_dashboard(doc); if(sys_defaults.supp_master_name == 'Supplier Name') @@ -35,7 +31,8 @@ cur_frm.cscript.make_dashboard = function(doc) { cur_frm.dashboard.reset(); if(doc.__islocal) return; - cur_frm.dashboard.set_headline('Loading...') + if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) + cur_frm.dashboard.set_headline('Loading...') cur_frm.dashboard.add_doctype_badge("Supplier Quotation", "supplier"); cur_frm.dashboard.add_doctype_badge("Purchase Order", "supplier"); @@ -49,12 +46,14 @@ cur_frm.cscript.make_dashboard = function(doc) { supplier: cur_frm.doc.name }, callback: function(r) { - cur_frm.dashboard.set_headline( - wn._("Total Billing This Year: ") + "" - + format_currency(r.message.total_billing, cur_frm.doc.default_currency) - + ' / ' + wn._("Unpaid") + ": " - + format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) - + ''); + if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { + cur_frm.dashboard.set_headline( + wn._("Total Billing This Year: ") + "" + + format_currency(r.message.total_billing, cur_frm.doc.default_currency) + + ' / ' + wn._("Unpaid") + ": " + + format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) + + ''); + } cur_frm.dashboard.set_badge_count(r.message); } }) diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js index d2c632530b..014efe6dbd 100644 --- a/selling/doctype/customer/customer.js +++ b/selling/doctype/customer/customer.js @@ -45,7 +45,8 @@ cur_frm.cscript.setup_dashboard = function(doc) { cur_frm.dashboard.reset(doc); if(doc.__islocal) return; - cur_frm.dashboard.set_headline(''+ wn._('Loading...')+ '') + if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) + cur_frm.dashboard.set_headline(''+ wn._('Loading...')+ '') cur_frm.dashboard.add_doctype_badge("Opportunity", "customer"); cur_frm.dashboard.add_doctype_badge("Quotation", "customer"); @@ -60,12 +61,14 @@ cur_frm.cscript.setup_dashboard = function(doc) { customer: cur_frm.doc.name }, callback: function(r) { - cur_frm.dashboard.set_headline( - wn._("Total Billing This Year: ") + "" - + format_currency(r.message.total_billing, cur_frm.doc.default_currency) - + ' / ' + wn._("Unpaid") + ": " - + format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) - + ''); + if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { + cur_frm.dashboard.set_headline( + wn._("Total Billing This Year: ") + "" + + format_currency(r.message.total_billing, cur_frm.doc.default_currency) + + ' / ' + wn._("Unpaid") + ": " + + format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) + + ''); + } cur_frm.dashboard.set_badge_count(r.message); } })