mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
[Report]Cleanup of territory target variance, sales person target variance & budget variance reports
This commit is contained in:
@@ -24,16 +24,22 @@ def execute(filters=None):
|
||||
columns = get_columns(filters)
|
||||
item_map = get_item_details()
|
||||
pl = get_price_list()
|
||||
last_purchase_rate = get_last_purchase_rate()
|
||||
bom_rate = get_item_bom_rate()
|
||||
val_rate_map = get_valuation_rate()
|
||||
|
||||
precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
|
||||
|
||||
data = []
|
||||
for item in sorted(item_map):
|
||||
data.append([item, item_map[item]["item_name"],
|
||||
item_map[item]["description"], item_map[item]["stock_uom"],
|
||||
flt(item_map[item]["last_purchase_rate"]), val_rate_map.get(item, 0),
|
||||
pl.get(item, {}).get("selling"), pl.get(item, {}).get("buying"),
|
||||
bom_rate.get(item, 0), flt(item_map[item]["standard_rate"])
|
||||
flt(last_purchase_rate.get(item, 0), precision),
|
||||
flt(val_rate_map.get(item, 0), precision),
|
||||
pl.get(item, {}).get("selling"),
|
||||
pl.get(item, {}).get("buying"),
|
||||
flt(bom_rate.get(item, 0), precision),
|
||||
flt(item_map[item]["standard_rate"])
|
||||
])
|
||||
|
||||
return columns, data
|
||||
@@ -53,7 +59,7 @@ def get_item_details():
|
||||
item_map = {}
|
||||
|
||||
for i in webnotes.conn.sql("select name, item_name, description, \
|
||||
stock_uom, standard_rate, last_purchase_rate from tabItem \
|
||||
stock_uom, standard_rate from tabItem \
|
||||
order by item_code", as_dict=1):
|
||||
item_map.setdefault(i.name, i)
|
||||
|
||||
@@ -84,24 +90,60 @@ def get_price_list():
|
||||
|
||||
return item_rate_map
|
||||
|
||||
def get_last_purchase_rate():
|
||||
|
||||
item_last_purchase_rate_map = {}
|
||||
|
||||
query = """select * from (select
|
||||
result.item_code,
|
||||
result.purchase_rate
|
||||
from (
|
||||
(select
|
||||
po_item.item_code,
|
||||
po_item.item_name,
|
||||
po.transaction_date as posting_date,
|
||||
po_item.purchase_ref_rate,
|
||||
po_item.discount_rate,
|
||||
po_item.purchase_rate
|
||||
from `tabPurchase Order` po, `tabPurchase Order Item` po_item
|
||||
where po.name = po_item.parent and po.docstatus = 1)
|
||||
union
|
||||
(select
|
||||
pr_item.item_code,
|
||||
pr_item.item_name,
|
||||
pr.posting_date,
|
||||
pr_item.purchase_ref_rate,
|
||||
pr_item.discount_rate,
|
||||
pr_item.purchase_rate
|
||||
from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pr_item
|
||||
where pr.name = pr_item.parent and pr.docstatus = 1)
|
||||
) result
|
||||
order by result.item_code asc, result.posting_date desc) result_wrapper
|
||||
group by item_code"""
|
||||
|
||||
for d in webnotes.conn.sql(query, as_dict=1):
|
||||
item_last_purchase_rate_map.setdefault(d.item_code, d.purchase_rate)
|
||||
|
||||
return item_last_purchase_rate_map
|
||||
|
||||
def get_item_bom_rate():
|
||||
"""Get BOM rate of an item from BOM"""
|
||||
|
||||
bom_map = {}
|
||||
item_bom_map = {}
|
||||
|
||||
for b in webnotes.conn.sql("""select item, (total_cost/quantity) as bom_rate
|
||||
from `tabBOM` where is_active=1 and is_default=1""", as_dict=1):
|
||||
bom_map.setdefault(b.item, flt(b.bom_rate))
|
||||
item_bom_map.setdefault(b.item, flt(b.bom_rate))
|
||||
|
||||
return bom_map
|
||||
return item_bom_map
|
||||
|
||||
def get_valuation_rate():
|
||||
"""Get an average valuation rate of an item from all warehouses"""
|
||||
|
||||
val_rate_map = {}
|
||||
item_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):
|
||||
val_rate_map.setdefault(d.item_code, d.val_rate)
|
||||
item_val_rate_map.setdefault(d.item_code, flt(d.val_rate))
|
||||
|
||||
return val_rate_map
|
||||
return item_val_rate_map
|
||||
Reference in New Issue
Block a user