Financial Reports

- Update formatter for use with DataTable
- Fetch Currency from  filters and fallback to company currency
This commit is contained in:
Faris Ansari 2018-07-20 15:11:55 +05:30
parent ce6e27a066
commit 5986d59b01
3 changed files with 27 additions and 22 deletions

View File

@ -11,6 +11,8 @@ def execute(filters=None):
period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
filters.periodicity, company=filters.company)
currency = filters.presentation_currency or frappe.db.get_value("Company", filters.company, "default_currency")
asset = get_data(filters.company, "Asset", "Debit", period_list,
only_current_fiscal_year=False, filters=filters,
accumulated_values=filters.accumulated_values)
@ -24,7 +26,7 @@ def execute(filters=None):
accumulated_values=filters.accumulated_values)
provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity,
period_list, filters.company)
period_list, filters.company, currency)
message, opening_balance = check_opening_balance(asset, liability, equity)
@ -37,7 +39,7 @@ def execute(filters=None):
"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
"account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
"warn_if_negative": True,
"currency": frappe.db.get_value("Company", filters.company, "default_currency")
"currency": currency
}
for period in period_list:
unclosed[period.key] = opening_balance
@ -58,12 +60,12 @@ def execute(filters=None):
return columns, data, message, chart
def get_provisional_profit_loss(asset, liability, equity, period_list, company, consolidated=False):
def get_provisional_profit_loss(asset, liability, equity, period_list, company, currency=None, consolidated=False):
provisional_profit_loss = {}
total_row = {}
if asset and (liability or equity):
total = total_row_total=0
currency = frappe.db.get_value("Company", company, "default_currency")
currency = currency or frappe.db.get_value("Company", company, "default_currency")
total_row = {
"account_name": "'" + _("Total (Credit)") + "'",
"account": "'" + _("Total (Credit)") + "'",

View File

@ -59,20 +59,21 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"fieldtype": "Check"
}
],
"formatter": function(row, cell, value, columnDef, dataContext, default_formatter) {
if (columnDef.df.fieldname=="account") {
value = dataContext.account_name;
"formatter": function(value, row, column, data, default_formatter) {
if (column.fieldname=="account") {
value = data.account_name;
columnDef.df.link_onclick =
"frappe.query_reports['Profitability Analysis'].open_profit_and_loss_statement(" + JSON.stringify(dataContext) + ")";
columnDef.df.is_tree = true;
column.link_onclick =
"frappe.query_reports['Profitability Analysis'].open_profit_and_loss_statement(" + JSON.stringify(data) + ")";
column.is_tree = true;
}
value = default_formatter(row, cell, value, columnDef, dataContext);
value = default_formatter(value, row, column, data);
if (!dataContext.parent_account && dataContext.based_on != 'project') {
if (!data.parent_account && data.based_on != 'project') {
value = $(`<span>${value}</span>`);
var $value = $(value).css("font-weight", "bold");
if (dataContext.warn_if_negative && dataContext[columnDef.df.fieldname] < 0) {
if (data.warn_if_negative && data[columnDef.df.fieldname] < 0) {
$value.addClass("text-danger");
}

View File

@ -2,20 +2,22 @@ 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;
"formatter": function(value, row, column, data, default_formatter) {
if (column.fieldname=="account") {
value = data.account_name;
columnDef.df.link_onclick =
"erpnext.financial_statements.open_general_ledger(" + JSON.stringify(dataContext) + ")";
columnDef.df.is_tree = true;
column.link_onclick =
"erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")";
column.is_tree = true;
}
value = default_formatter(row, cell, value, columnDef, dataContext);
value = default_formatter(value, row, column, data);
if (!data.parent_account) {
value = $(`<span>${value}</span>`);
if (!dataContext.parent_account) {
var $value = $(value).css("font-weight", "bold");
if (dataContext.warn_if_negative && dataContext[columnDef.df.fieldname] < 0) {
if (data.warn_if_negative && data[column.fieldname] < 0) {
$value.addClass("text-danger");
}