[report]general ledger report migrated to script report

This commit is contained in:
Nabin Hait 2013-12-06 16:36:23 +05:30
parent 86da17d5d9
commit c313ca99ff
4 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,51 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
wn.query_reports["General Ledger"] = {
"filters": [
{
"fieldname":"company",
"label": wn._("Company"),
"fieldtype": "Link",
"options": "Company",
"default": wn.defaults.get_user_default("company"),
"reqd": 1
},
{
"fieldname":"account",
"label": wn._("Account"),
"fieldtype": "Link",
"options": "Account"
},
{
"fieldname":"voucher_no",
"label": wn._("Voucher No"),
"fieldtype": "Data",
},
{
"fieldtype": "Break",
},
{
"fieldname":"from_date",
"label": wn._("From Date"),
"fieldtype": "Date",
"default": wn.datetime.add_months(wn.datetime.get_today(), -1),
"reqd": 1,
"width": "60px"
},
{
"fieldname":"to_date",
"label": wn._("To Date"),
"fieldtype": "Date",
"default": wn.datetime.get_today(),
"reqd": 1,
"width": "60px"
},
{
"fieldname":"group_by",
"label": wn._("Group by"),
"fieldtype": "Select",
"options": "\nAccount\nVoucher"
}
]
}

View File

@ -0,0 +1,49 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt
def execute(filters=None):
columns = get_columns()
if filters.get("group_by"):
data = get_grouped_gle(filters)
else:
data = get_gl_entries(filters)
return columns, data
def get_columns():
return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Currency:100",
"Credit:Currency:100", "Voucher Type::120", "Voucher No::160", "Remarks::200"]
def get_gl_entries(filters):
return webnotes.conn.sql("""select
posting_date, account, debit, credit, voucher_type, voucher_no, cost_center, remarks
from `tabGL Entry`
where company=%(company)s
and posting_date between %(from_date)s and %(to_date)s
{conditions}
order by posting_date, account"""\
.format(conditions=get_conditions(filters)), filters)
def get_conditions(filters):
return " and account=%(account)s" if filters.get("account") else ""
def get_grouped_gle(filters):
gle_map = {}
gle = get_gl_entries(filters)
for d in gle:
gle_map.setdefault(d[1 if filters["group_by"]=="Account" else 5], []).append(d)
data = []
for entries in gle_map.values():
total_debit = total_credit = 0.0
for entry in entries:
data.append(entry)
total_debit += flt(entry[2])
total_credit += flt(entry[3])
data.append(["", "Total", total_debit, total_credit, "", "", ""])
return data

View File

@ -0,0 +1,21 @@
[
{
"creation": "2013-12-06 13:22:23",
"docstatus": 0,
"modified": "2013-12-06 13:22:23",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "GL Entry",
"report_name": "General Ledger",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "General Ledger"
}
]