[report] fix via error report

This commit is contained in:
Rushabh Mehta 2015-04-13 11:30:10 +05:30
parent 2437d4cce2
commit b4c4351513
2 changed files with 26 additions and 24 deletions

View File

@ -29,7 +29,7 @@ frappe.query_reports["Payment Period Based On Invoice Date"] = {
options: "Account", options: "Account",
get_query: function() { get_query: function() {
return { return {
query: "erpnext.controllers.queries.get_account_list", query: "erpnext.controllers.queries.get_account_list",
filters: { filters: {
"report_type": "Balance Sheet", "report_type": "Balance Sheet",
company: frappe.query_report.filters_by_name.company.get_value() company: frappe.query_report.filters_by_name.company.get_value()
@ -42,7 +42,8 @@ frappe.query_reports["Payment Period Based On Invoice Date"] = {
label: __("Company"), label: __("Company"),
fieldtype: "Link", fieldtype: "Link",
options: "Company", options: "Company",
reqd: 1,
default: frappe.defaults.get_user_default("company") default: frappe.defaults.get_user_default("company")
}, },
] ]
} }

View File

@ -3,8 +3,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import msgprint, _ from frappe import _
from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
from frappe.utils import flt
def execute(filters=None): def execute(filters=None):
if not filters: filters = {} if not filters: filters = {}
@ -19,16 +20,16 @@ def execute(filters=None):
for d in entries: for d in entries:
if d.against_voucher: if d.against_voucher:
against_date = d.against_voucher and invoice_posting_date_map[d.against_voucher] or "" against_date = d.against_voucher and invoice_posting_date_map[d.against_voucher] or ""
outstanding_amount = d.debit or -1*d.credit outstanding_amount = flt(d.debit) or -1 * flt(d.credit)
else: else:
against_date = d.against_invoice and invoice_posting_date_map[d.against_invoice] or "" against_date = d.against_invoice and invoice_posting_date_map[d.against_invoice] or ""
outstanding_amount = d.credit or -1*d.debit outstanding_amount = flt(d.credit) or -1 * flt(d.debit)
row = [d.name, d.account, d.posting_date, d.against_voucher or d.against_invoice, row = [d.name, d.account, d.posting_date, d.against_voucher or d.against_invoice,
against_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark] against_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
if d.against_voucher or d.against_invoice: if d.against_voucher or d.against_invoice:
row += get_ageing_data(d.posting_date, against_date, outstanding_amount) row += get_ageing_data(30, 60, 90, d.posting_date, against_date, outstanding_amount)
else: else:
row += ["", "", "", "", ""] row += ["", "", "", "", ""]
@ -46,40 +47,40 @@ def get_columns():
def get_conditions(filters): def get_conditions(filters):
conditions = "" conditions = ""
party_accounts = [] party = None
if filters.get("account"): if filters.get("account"):
party_accounts = [filters["account"]] party = filters["account"]
else: else:
cond = filters.get("company") and (" and company = '%s'" % conditions += " and company = '%s'" % frappe.db.escape(filters["company"])
filters["company"].replace("'", "\'")) or ""
if filters.get("payment_type") == "Incoming": account_type = "Receivable" if filters.get("payment_type") == "Incoming" else "Payable"
cond += " and master_type = 'Customer'"
else:
cond += " and master_type = 'Supplier'"
party_accounts = frappe.db.sql_list("""select name from `tabAccount` conditions += """ and account in
where ifnull(master_name, '')!='' and docstatus < 2 %s""" % cond) (select name from tabAccount
where account_type = '{0}'
and company='{1}')""".format(account_type, frappe.db.escape(filters["company"]))
if party_accounts: if party:
conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(party_accounts))) conditions += " and jvd.party = '%s'" % frappe.db.escape(party)
else: else:
msgprint(_("No Customer or Supplier Accounts found"), raise_exception=1) conditions += " and ifnull(jvd.party, '') != ''"
if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"] if filters.get("from_date"):
if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"] conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
if filters.get("to_date"):
conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
return conditions, party_accounts return conditions
def get_entries(filters): def get_entries(filters):
conditions, party_accounts = get_conditions(filters) conditions = get_conditions(filters)
entries = frappe.db.sql("""select jv.name, jvd.account, jv.posting_date, entries = frappe.db.sql("""select jv.name, jvd.account, jv.posting_date,
jvd.against_voucher, jvd.against_invoice, jvd.debit, jvd.credit, jvd.against_voucher, jvd.against_invoice, jvd.debit, jvd.credit,
jv.cheque_no, jv.cheque_date, jv.remark jv.cheque_no, jv.cheque_date, jv.remark
from `tabJournal Entry Account` jvd, `tabJournal Entry` jv from `tabJournal Entry Account` jvd, `tabJournal Entry` jv
where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" % where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" %
(conditions), tuple(party_accounts), as_dict=1) conditions, as_dict=1, debug=1)
return entries return entries