From b4c4351513c42201c30e4427d7145355a3328f25 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 13 Apr 2015 11:30:10 +0530 Subject: [PATCH] [report] fix via error report --- .../payment_period_based_on_invoice_date.js | 5 ++- .../payment_period_based_on_invoice_date.py | 45 ++++++++++--------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js index a15d86b2d4..fd03cc35ca 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js @@ -29,7 +29,7 @@ frappe.query_reports["Payment Period Based On Invoice Date"] = { options: "Account", get_query: function() { return { - query: "erpnext.controllers.queries.get_account_list", + query: "erpnext.controllers.queries.get_account_list", filters: { "report_type": "Balance Sheet", 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"), fieldtype: "Link", options: "Company", + reqd: 1, default: frappe.defaults.get_user_default("company") }, ] -} \ No newline at end of file +} diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py index 8501ed33ed..fdd6e1a27d 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py @@ -3,8 +3,9 @@ from __future__ import unicode_literals import frappe -from frappe import msgprint, _ +from frappe import _ from erpnext.accounts.report.accounts_receivable.accounts_receivable import get_ageing_data +from frappe.utils import flt def execute(filters=None): if not filters: filters = {} @@ -19,16 +20,16 @@ def execute(filters=None): for d in entries: if d.against_voucher: 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: 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, against_date, d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark] 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: row += ["", "", "", "", ""] @@ -46,40 +47,40 @@ def get_columns(): def get_conditions(filters): conditions = "" - party_accounts = [] + party = None if filters.get("account"): - party_accounts = [filters["account"]] + party = filters["account"] else: - cond = filters.get("company") and (" and company = '%s'" % - filters["company"].replace("'", "\'")) or "" + conditions += " and company = '%s'" % frappe.db.escape(filters["company"]) - if filters.get("payment_type") == "Incoming": - cond += " and master_type = 'Customer'" - else: - cond += " and master_type = 'Supplier'" + account_type = "Receivable" if filters.get("payment_type") == "Incoming" else "Payable" - party_accounts = frappe.db.sql_list("""select name from `tabAccount` - where ifnull(master_name, '')!='' and docstatus < 2 %s""" % cond) + conditions += """ and account in + (select name from tabAccount + where account_type = '{0}' + and company='{1}')""".format(account_type, frappe.db.escape(filters["company"])) - if party_accounts: - conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(party_accounts))) + if party: + conditions += " and jvd.party = '%s'" % frappe.db.escape(party) 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("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"] + if filters.get("from_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): - conditions, party_accounts = get_conditions(filters) + conditions = get_conditions(filters) entries = frappe.db.sql("""select jv.name, jvd.account, jv.posting_date, jvd.against_voucher, jvd.against_invoice, jvd.debit, jvd.credit, jv.cheque_no, jv.cheque_date, jv.remark from `tabJournal Entry Account` jvd, `tabJournal Entry` jv 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