I am creating a Script Report. In that report, I am trying to add report_summary. First I am trying to add sample report_summary. But It shows black space. My code is -
from frappe import _, msgprint
import frappe
import datetime
def execute(filters=None):
return get_columns(filters), get_data(filters), report_summary
def get_data(filters):
conditions=get_conditions(filters)
query = frappe.db.sql("""SELECT t1.lot_name, t2.item_code as 'Item',
ROUND(t2.amount, 2) as 'Purchase Amount',
ROUND(sum(t3.amount),2) as 'Sales Amount',
CASE WHEN (sum(t3.amount) - t2.amount) <= 0
THEN '' ELSE
ROUND((sum(t3.amount) - t2.amount),2) END as 'Profit',
CASE WHEN (t2.amount - sum(t3.amount)) <= 0
THEN '' ELSE
ROUND((t2.amount - sum(t3.amount)),2) END as 'Loss'
FROM `tabPurchase Order` as t1
JOIN `tabPurchase Order Item` as t2 ON t1.name = t2.parent
JOIN `tabSales Order Item` as t3 ON t1.lot_name = t3.lot_no
WHERE t3.docstatus = 1 AND t1.docstatus = 1 %s GROUP BY t1.lot_name, t2.item_code""" %(conditions), filters, as_list=1);
return query
def get_conditions(filters):
conditions = ""
if filters.get("item_code"):
conditions += " and t2.item_code = %(item_code)s"
if filters.get("lot_name"):
conditions += " and t1.lot_name = %(lot_name)s"
if filters.date_from_filter and filters.date_to_filter:
if filters.date_from_filter > filters.date_to_filter:
frappe.throw("The 'From Date' ({}) must be before the 'To Date' ({})".format(filters.date_from_filter, filters.date_to_filter))
if filters.date_from_filter == None:
filters.date_from_filter = "2000-01-01"
if filters.date_to_filter == None:
filters.date_to_filter = frappe.datetime.get_today()
conditions += " and t3.transaction_date BETWEEN '" + filters.date_from_filter + "' AND '" + filters.date_to_filter + "'"
return conditions
def get_columns(filters):
return [
{
'fieldname':'lot_name',
'label': _('LOT No.'),
'fieldtype':'Data',
'width':'140'
},
{
'fieldname':'item_code',
'label': _('Item'),
'fieldtype':'Data',
'width':'140'
},
{
'fieldname':'purchase_amount',
'label': _('Purchase Amount'),
'fieldtype':'Currency',
'width':'150'
},
{
'fieldname':'sales_amount',
'label': _('Sales Amount'),
'fieldtype':'Currency',
'width':'150'
},
{
'fieldname':'profit',
'label': _('Profit'),
'fieldtype':'Float',
'width':'150'
},
{
'fieldname':'loss',
'label': _('Loss'),
'fieldtype':'Float',
'width':'200'
}
]
report_summary = [
{"label":"cats","value":2287,'indicator':'Red'},
{"label":"dogs","value":3647,'indicator':'Blue'}
]
Here is the output
If anyone face this issue and solved it, please help