[fix] [minor] all types of variance reports fixed

This commit is contained in:
Akhilesh Darjee 2013-11-13 16:45:11 +05:30
parent 49f2bafa0f
commit bfe264be8c
3 changed files with 29 additions and 18 deletions

View File

@ -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]

View File

@ -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

View File

@ -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