[fix] [minor] all types of variance reports fixed
diff --git a/accounts/report/budget_variance_report/budget_variance_report.py b/accounts/report/budget_variance_report/budget_variance_report.py
index c1c4bc1..f4665ec 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 @@
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 6fdafe0..d2220f4 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 @@
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_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 @@
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 @@
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 829f781..72657f0 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 @@
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 @@
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 @@
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_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 @@
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