[fix] Vehicle expense report not working

This commit is contained in:
Rohit Waghchaure 2017-04-10 12:09:18 +05:30 committed by Nabin Hait
parent 768a888bf2
commit 1ff1368280
2 changed files with 24 additions and 36 deletions

View File

@ -22,18 +22,6 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
query_report.trigger_refresh(); query_report.trigger_refresh();
}); });
} }
},
{
"fieldname": "from_date",
"label": __("From Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_start_date"),
},
{
"fieldname": "to_date",
"label": __("To Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_end_date"),
} }
] ]
} }

View File

@ -3,41 +3,41 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import erpnext
from frappe import _ from frappe import _
from frappe.utils import flt,cstr from frappe.utils import flt,cstr
from erpnext.accounts.report.financial_statements import get_period_list from erpnext.accounts.report.financial_statements import get_period_list
def execute(filters=None): def execute(filters=None):
period_list = get_period_list(2016, 2016,"Monthly")
for period in period_list:
pass
columns, data = [], [] columns, data = [], []
columns=get_columns() if filters.get('fiscal_year'):
data=get_log_data(filters) company = erpnext.get_default_company()
chart=get_chart_data(data,period_list) period_list = get_period_list(filters.get('fiscal_year'), filters.get('fiscal_year'),"Monthly", company)
columns=get_columns()
data=get_log_data(filters)
chart=get_chart_data(data,period_list)
return columns, data, None, chart return columns, data, None, chart
def get_columns(): def get_columns():
columns = [_("License") + ":Link/Vehicle:100", _("Make") + ":data:50", columns = [_("License") + ":Link/Vehicle:100", _("Make") + ":data:50",
_("Model") + ":data:50", _("Location") + ":data:100", _("Model") + ":data:50", _("Location") + ":data:100",
_("Log") + ":Link/Vehicle Log:100", _("Odometer") + ":Int:80", _("Log") + ":Link/Vehicle Log:100", _("Odometer") + ":Int:80",
_("Date") + ":Date:100", _("Fuel Qty") + ":Float:80", _("Date") + ":Date:100", _("Fuel Qty") + ":Float:80",
_("Fuel Price") + ":Float:100",_("Service Expense") + ":Float:100" _("Fuel Price") + ":Float:100",_("Service Expense") + ":Float:100"
] ]
return columns return columns
def get_log_data(filters): def get_log_data(filters):
conditions="" fy = frappe.db.get_value('Fiscal Year', filters.get('fiscal_year'), ['year_start_date', 'year_end_date'], as_dict=True)
if filters.from_date: data = frappe.db.sql("""select
conditions += " and date >= %(from_date)s" vhcl.license_plate as "License", vhcl.make as "Make", vhcl.model as "Model",
if filters.to_date: vhcl.location as "Location", log.name as "Log", log.odometer as "Odometer",
conditions += " and date <= %(to_date)s" log.date as "Date", log.fuel_qty as "Fuel Qty", log.price as "Fuel Price"
data = frappe.db.sql("""select vhcl.license_plate as "License",vhcl.make as "Make",vhcl.model as "Model", from
vhcl.location as "Location",log.name as "Log",log.odometer as "Odometer",log.date as "Date", `tabVehicle` vhcl,`tabVehicle Log` log
log.fuel_qty as "Fuel Qty",log.price as "Fuel Price" where
from `tabVehicle` vhcl,`tabVehicle Log` log vhcl.license_plate = log.license_plate and log.docstatus = 1 and date between %s and %s
where vhcl.license_plate = log.license_plate and log.docstatus = 1 %s order by date""" ,(fy.year_start_date, fy.year_end_date), as_dict=1)
order by date""" % (conditions,),filters, as_dict=1)
dl=list(data) dl=list(data)
for row in dl: for row in dl:
row["Service Expense"]= get_service_expense(row["Log"]) row["Service Expense"]= get_service_expense(row["Log"])
@ -45,8 +45,8 @@ def get_log_data(filters):
def get_service_expense(logname): def get_service_expense(logname):
expense_amount = frappe.db.sql("""select sum(expense_amount) expense_amount = frappe.db.sql("""select sum(expense_amount)
from `tabVehicle Log` log,`tabVehicle Service` ser from `tabVehicle Log` log,`tabVehicle Service` ser
where ser.parent=log.name and log.name=%s""",logname) where ser.parent=log.name and log.name=%s""",logname)
return flt(expense_amount[0][0]) if expense_amount else 0 return flt(expense_amount[0][0]) if expense_amount else 0
def get_chart_data(data,period_list): def get_chart_data(data,period_list):