brotherton-erpnext/erpnext/public/js/financial_statements.js
tundebabzy c89782502c Report presentation currency (#12670)
* Add new Select to filters

* get the currencies from database rather than hardcoded

* label report columns:
- If presentation currency is available in filters, use it or
- If company is available in filters, use it or
- use default company currency

* add new function - get_currency

* tweak new function `get_currency`

* add new function `convert` to convert a value to another currency

* add new function `convert_to_presentation_currency`

* clean up `get_currency` first pass

* memoise the exchange rates

* limit fetched GL entries to to_date

* check if account type is p&l or not and use appropriate exchange rate based on that

* change EXCHANGE RATE to a dict, use for memoisation

* rename EXCHANGE_RATE

* cache exchange rates and use them as needed

* add docstrings

* add presentation currency logic to financial statement reports

* move new functions from `general_ledger.py` to new module

* clean up

* PEP 8 clean up

* move function to util.py

* PEP 8 clean up

* remove presentation currency option from cashflow

* adjust currency as needed

* allow users to save presentation currency in Accounts Settings

* add new function `get_presentation_currency_list`

* refactor query_report modules with no promises

* Revert "allow users to save presentation currency in Accounts Settings"

This reverts commit 3b58a6296cf3f7b4d80ac55b03f9d5d4887b796b.

* show print page in correct currency

* Update utils.py
2018-02-12 15:04:50 +05:30

114 lines
3.5 KiB
JavaScript

frappe.provide("erpnext.financial_statements");
erpnext.financial_statements = {
"filters": get_filters(),
"formatter": function(row, cell, value, columnDef, dataContext, default_formatter) {
if (columnDef.df.fieldname=="account") {
value = dataContext.account_name;
columnDef.df.link_onclick =
"erpnext.financial_statements.open_general_ledger(" + JSON.stringify(dataContext) + ")";
columnDef.df.is_tree = true;
}
value = default_formatter(row, cell, value, columnDef, dataContext);
if (!dataContext.parent_account) {
var $value = $(value).css("font-weight", "bold");
if (dataContext.warn_if_negative && dataContext[columnDef.df.fieldname] < 0) {
$value.addClass("text-danger");
}
value = $value.wrap("<p></p>").parent().html();
}
return value;
},
"open_general_ledger": function(data) {
if (!data.account) return;
var project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; })
frappe.route_options = {
"account": data.account,
"company": frappe.query_report_filters_by_name.company.get_value(),
"from_date": data.from_date || data.year_start_date,
"to_date": data.to_date || data.year_end_date,
"project": (project && project.length > 0) ? project[0].$input.val() : ""
};
frappe.set_route("query-report", "General Ledger");
},
"tree": true,
"name_field": "account",
"parent_field": "parent_account",
"initial_depth": 3,
onload: function(report) {
// dropdown for links to other financial statements
erpnext.financial_statements.filters = get_filters()
report.page.add_inner_button(__("Balance Sheet"), function() {
var filters = report.get_values();
frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
}, __('Financial Statements'));
report.page.add_inner_button(__("Profit and Loss"), function() {
var filters = report.get_values();
frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
}, __('Financial Statements'));
report.page.add_inner_button(__("Cash Flow Statement"), function() {
var filters = report.get_values();
frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
}, __('Financial Statements'));
}
};
function get_filters(){
return [
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"default": frappe.defaults.get_user_default("Company"),
"reqd": 1
},
{
"fieldname":"from_fiscal_year",
"label": __("Start Year"),
"fieldtype": "Link",
"options": "Fiscal Year",
"default": frappe.defaults.get_user_default("fiscal_year"),
"reqd": 1
},
{
"fieldname":"to_fiscal_year",
"label": __("End Year"),
"fieldtype": "Link",
"options": "Fiscal Year",
"default": frappe.defaults.get_user_default("fiscal_year"),
"reqd": 1
},
{
"fieldname": "periodicity",
"label": __("Periodicity"),
"fieldtype": "Select",
"options": [
{ "value": "Monthly", "label": __("Monthly") },
{ "value": "Quarterly", "label": __("Quarterly") },
{ "value": "Half-Yearly", "label": __("Half-Yearly") },
{ "value": "Yearly", "label": __("Yearly") }
],
"default": "Monthly",
"reqd": 1
},
// Note:
// If you are modifying this array such that the presentation_currency object
// is no longer the last object, please make adjustments in cash_flow.js
// accordingly.
{
"fieldname": "presentation_currency",
"label": __("Currency"),
"fieldtype": "Select",
"options": erpnext.get_presentation_currency_list()
}
]
}