add presentation currency logic to financial statement reports

This commit is contained in:
tundebabzy
2018-01-23 15:44:26 +01:00
parent 9b41ec4d3e
commit ecaa0f427e
7 changed files with 121 additions and 46 deletions

View File

@@ -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
});
});
});

View File

@@ -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
});
});
});

View File

@@ -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)

View File

@@ -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)

View File

@@ -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));

View File

@@ -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)

View File

@@ -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
}
);
});
}
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
}
);
});
});