From e25dcd27370f81a9d4f3ee5bb856eea6e902c914 Mon Sep 17 00:00:00 2001 From: Zarrar Date: Thu, 21 Jun 2018 10:53:12 +0530 Subject: [PATCH] [Minor] Report related fixes (#14620) * fix in query incase list is empty * periodicity not found error when called from consolidated financial statements and custom cash flow is activated * unset currency filter to apply default currency or so * python 2 - 3 fix --- .../report/cash_flow/custom_cash_flow.py | 31 ++++++++++--------- erpnext/public/js/utils.js | 3 +- .../address_and_contacts.py | 4 +-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/report/cash_flow/custom_cash_flow.py b/erpnext/accounts/report/cash_flow/custom_cash_flow.py index 160b200142..ee0f38c1c8 100644 --- a/erpnext/accounts/report/cash_flow/custom_cash_flow.py +++ b/erpnext/accounts/report/cash_flow/custom_cash_flow.py @@ -25,15 +25,14 @@ def get_mappers_from_db(): def get_accounts_in_mappers(mapping_names): - return frappe.db.sql( - 'select cfma.name, cfm.label, cfm.is_working_capital, cfm.is_income_tax_liability, ' - 'cfm.is_income_tax_expense, cfm.is_finance_cost, cfm.is_finance_cost_adjustment ' - 'from `tabCash Flow Mapping Accounts` cfma ' - 'join `tabCash Flow Mapping` cfm on cfma.parent=cfm.name ' - 'where cfma.parent in %s ' - 'order by cfm.is_working_capital', - (mapping_names,) - ) + return frappe.db.sql(''' + select cfma.name, cfm.label, cfm.is_working_capital, cfm.is_income_tax_liability, + cfm.is_income_tax_expense, cfm.is_finance_cost, cfm.is_finance_cost_adjustment + from `tabCash Flow Mapping Accounts` cfma + join `tabCash Flow Mapping` cfm on cfma.parent=cfm.name + where cfma.parent in (%s) + order by cfm.is_working_capital + ''', (', '.join(['"%s"' % d for d in mapping_names]))) def setup_mappers(mappers): @@ -334,6 +333,7 @@ def compute_data(filters, company_currency, profit_data, period_list, light_mapp def execute(filters=None): + if not filters.periodicity: filters.periodicity = "Monthly" period_list = get_period_list( filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity, filters.accumulated_values, filters.company @@ -376,6 +376,7 @@ def _get_account_type_based_data(filters, account_names, period_list, accumulate total = 0 for period in period_list: start_date = get_start_date(period, accumulated_values, company) + accounts = ', '.join(['"%s"' % d for d in account_names]) if opening_balances: date_info = dict(date=start_date) @@ -397,19 +398,19 @@ def _get_account_type_based_data(filters, account_names, period_list, accumulate from `tabGL Entry` where company=%s and posting_date >= %s and posting_date <= %s and voucher_type != 'Period Closing Voucher' - and account in ( SELECT name FROM tabAccount WHERE name IN %s - OR parent_account IN %s) - """, (company, start, end, account_names, account_names)) + and account in ( SELECT name FROM tabAccount WHERE name IN (%s) + OR parent_account IN (%s)) + """, (company, start, end, accounts, accounts)) else: gl_sum = frappe.db.sql_list(""" select sum(credit) - sum(debit) from `tabGL Entry` where company=%s and posting_date >= %s and posting_date <= %s and voucher_type != 'Period Closing Voucher' - and account in ( SELECT name FROM tabAccount WHERE name IN %s - OR parent_account IN %s) + and account in ( SELECT name FROM tabAccount WHERE name IN (%s) + OR parent_account IN (%s)) """, (company, start_date if accumulated_values else period['from_date'], - period['to_date'], account_names, account_names)) + period['to_date'], accounts, accounts)) if gl_sum and gl_sum[0]: amount = gl_sum[0] diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 01c4943b3a..1f7cca178f 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -15,7 +15,8 @@ $.extend(erpnext, { get_presentation_currency_list: () => { const docs = frappe.boot.docs; - const currency_list = docs.filter(d => d.doctype === ":Currency").map(d => d.name); + let currency_list = docs.filter(d => d.doctype === ":Currency").map(d => d.name); + currency_list.unshift(""); return currency_list; }, diff --git a/erpnext/selling/report/address_and_contacts/address_and_contacts.py b/erpnext/selling/report/address_and_contacts/address_and_contacts.py index 0a46d2c36f..a9e43034b4 100644 --- a/erpnext/selling/report/address_and_contacts/address_and_contacts.py +++ b/erpnext/selling/report/address_and_contacts/address_and_contacts.py @@ -77,8 +77,8 @@ def get_party_addresses_and_contact(party_type, party, party_group): result.extend(add_blank_columns_for("Address")) data.append(result) else: - addresses = map(list, addresses) - contacts = map(list, contacts) + addresses = list(map(list, addresses)) + contacts = list(map(list, contacts)) max_length = max(len(addresses), len(contacts)) for idx in range(0, max_length):