brotherton-erpnext/erpnext/accounts/report/general_ledger/general_ledger.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

117 lines
2.8 KiB
JavaScript

// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
frappe.query_reports["General Ledger"] = {
"filters": [
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"default": frappe.defaults.get_user_default("Company"),
"reqd": 1
},
{
"fieldname":"from_date",
"label": __("From Date"),
"fieldtype": "Date",
"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
"reqd": 1,
"width": "60px"
},
{
"fieldname":"to_date",
"label": __("To Date"),
"fieldtype": "Date",
"default": frappe.datetime.get_today(),
"reqd": 1,
"width": "60px"
},
{
"fieldname":"account",
"label": __("Account"),
"fieldtype": "Link",
"options": "Account",
"get_query": function() {
var company = frappe.query_report_filters_by_name.company.get_value();
return {
"doctype": "Account",
"filters": {
"company": company,
}
}
}
},
{
"fieldname":"voucher_no",
"label": __("Voucher No"),
"fieldtype": "Data",
},
{
"fieldname":"project",
"label": __("Project"),
"fieldtype": "Link",
"options": "Project"
},
{
"fieldtype": "Break",
},
{
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
"default": ""
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"get_options": function() {
var party_type = frappe.query_report_filters_by_name.party_type.get_value();
var party = frappe.query_report_filters_by_name.party.get_value();
if(party && !party_type) {
frappe.throw(__("Please select Party Type first"));
}
return party_type;
},
on_change: function() {
var party_type = frappe.query_report_filters_by_name.party_type.get_value();
var party = frappe.query_report_filters_by_name.party.get_value();
if(!party_type || !party) {
frappe.query_report_filters_by_name.party_name.set_value("");
return;
}
var fieldname = frappe.scrub(party_type) + "_name";
frappe.db.get_value(party_type, party, fieldname, function(value) {
frappe.query_report_filters_by_name.party_name.set_value(value[fieldname]);
});
}
},
{
"fieldname":"party_name",
"label": __("Party Name"),
"fieldtype": "Data",
"hidden": 1
},
{
"fieldname":"group_by_voucher",
"label": __("Group by Voucher"),
"fieldtype": "Check",
"default": 1
},
{
"fieldname":"group_by_account",
"label": __("Group by Account"),
"fieldtype": "Check",
},
{
"fieldname": "presentation_currency",
"label": __("Currency"),
"fieldtype": "Select",
"options": erpnext.get_presentation_currency_list()
}
]
}