diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js index 760fa649e67..b0716702271 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.js +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js @@ -1,15 +1,36 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Balance Sheet"] = erpnext.financial_statements; +const get_currencies = () => { + // frappe.db.get_list returns a Promise + return frappe.db.get_list('GL Entry', + { + distinct: true, + fields:['account_currency'], + as_list: true + } + ); +} - frappe.query_reports["Balance Sheet"]["filters"].push({ - "fieldname": "accumulated_values", - "label": __("Accumulated Values"), - "fieldtype": "Check", - "default": 1 +const flatten = (array) => { + return [].concat.apply([], array); +} + +get_currencies().then(currency_list => flatten(currency_list)).then(currency_list => { + frappe.require("assets/erpnext/js/financial_statements.js", function() { + frappe.query_reports["Balance Sheet"] = erpnext.financial_statements; + + frappe.query_reports["Balance Sheet"]["filters"].push({ + "fieldname": "accumulated_values", + "label": __("Accumulated Values"), + "fieldtype": "Check", + "default": 1 + }, + { + "fieldname": "presentation_currency", + "label": __("Currency"), + "fieldtype": "Select", + "options": currency_list + }); }); }); - - diff --git a/erpnext/accounts/report/cash_flow/cash_flow.js b/erpnext/accounts/report/cash_flow/cash_flow.js index 455664ffea9..fae55a2ccbe 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.js +++ b/erpnext/accounts/report/cash_flow/cash_flow.js @@ -1,13 +1,36 @@ // Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Cash Flow"] = $.extend({}, - erpnext.financial_statements); +const get_currencies = () => { + // frappe.db.get_list returns a Promise + return frappe.db.get_list('GL Entry', + { + distinct: true, + fields:['account_currency'], + as_list: true + } + ); +} - frappe.query_reports["Cash Flow"]["filters"].push({ - "fieldname": "accumulated_values", - "label": __("Accumulated Values"), - "fieldtype": "Check" +const flatten = (array) => { + return [].concat.apply([], array); +} + +get_currencies().then(currency_list => flatten(currency_list)).then(currency_list => { + frappe.require("assets/erpnext/js/financial_statements.js", function() { + frappe.query_reports["Cash Flow"] = $.extend({}, + erpnext.financial_statements); + + frappe.query_reports["Cash Flow"]["filters"].push({ + "fieldname": "accumulated_values", + "label": __("Accumulated Values"), + "fieldtype": "Check" + }, + { + "fieldname": "presentation_currency", + "label": __("Currency"), + "fieldtype": "Select", + "options": currency_list + }); }); }); \ No newline at end of file diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index f55d1927318..78c4e0f48b9 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -51,9 +51,9 @@ def execute(filters=None): # compute net profit / loss income = get_data(filters.company, "Income", "Credit", period_list, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) + accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True, filters=filters) expense = get_data(filters.company, "Expense", "Debit", period_list, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) + accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True, filters=filters) net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index b0c49dfbd81..14b94a732a1 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -4,6 +4,8 @@ from __future__ import unicode_literals import frappe import re + +from erpnext.accounts.report.general_ledger.general_ledger import convert_to_presentation_currency, get_currency from frappe import _ from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff, add_months, add_days, formatdate, cint) @@ -305,7 +307,7 @@ def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, f additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters) - gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year from `tabGL Entry` + gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry` where company=%(company)s {additional_conditions} and posting_date <= %(to_date)s @@ -321,6 +323,10 @@ def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, f }, as_dict=True) + if filters and filters.get('presentation_currency'): + gl = convert_to_presentation_currency(gl_entries, get_currency(filters)) + print('presentation currency - ', gl[0:2]) + for entry in gl_entries: gl_entries_by_account.setdefault(entry.account, []).append(entry) diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index 3e39afc3d9f..3e881ce68a9 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -1,4 +1,4 @@ -// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt const get_currencies = () => { @@ -16,9 +16,7 @@ const flatten = (array) => { return [].concat.apply([], array); } -get_currencies() -.then((r) => flatten(r)) -.then((currency_list) => { +const show_report = (currency_list) => { frappe.query_reports["General Ledger"] = { "filters": [ { @@ -132,4 +130,8 @@ get_currencies() } ] } -}); +} + +get_currencies() +.then((currency_list) => flatten(currency_list)) +.then((currency_list) => show_report(currency_list)); \ No newline at end of file diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index de0af607cb8..e8133f4ae6b 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -153,7 +153,7 @@ def get_currency(filters): company = get_appropriate_company(filters) company_currency = get_company_currency(company) presentation_currency = filters['presentation_currency'] if filters.get('presentation_currency') else company_currency - report_date = filters['to_date'] + report_date = filters.get('to_date') or filters.get('to_fiscal_year') currency_map = dict(company=company, company_currency=company_currency, presentation_currency=presentation_currency, report_date=report_date) diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js index bcac2dffa43..e020db1a427 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js @@ -1,27 +1,50 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Profit and Loss Statement"] = $.extend({}, - erpnext.financial_statements); - - frappe.query_reports["Profit and Loss Statement"]["filters"].push( +const get_currencies = () => { + // frappe.db.get_list returns a Promise + return frappe.db.get_list('GL Entry', { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center" - }, - { - "fieldname":"project", - "label": __("Project"), - "fieldtype": "Link", - "options": "Project" - }, - { - "fieldname": "accumulated_values", - "label": __("Accumulated Values"), - "fieldtype": "Check" + distinct: true, + fields:['account_currency'], + as_list: true } ); -}); \ No newline at end of file +} + +const flatten = (array) => { + return [].concat.apply([], array); +} + +get_currencies().then(currency_list => flatten(currency_list)).then(currency_list => { + frappe.require("assets/erpnext/js/financial_statements.js", function() { + frappe.query_reports["Profit and Loss Statement"] = $.extend({}, + erpnext.financial_statements); + + frappe.query_reports["Profit and Loss Statement"]["filters"].push( + { + "fieldname":"cost_center", + "label": __("Cost Center"), + "fieldtype": "Link", + "options": "Cost Center" + }, + { + "fieldname":"project", + "label": __("Project"), + "fieldtype": "Link", + "options": "Project" + }, + { + "fieldname": "accumulated_values", + "label": __("Accumulated Values"), + "fieldtype": "Check" + }, + { + "fieldname": "presentation_currency", + "label": __("Currency"), + "fieldtype": "Select", + "options": currency_list + } + ); + }); +});