From 226a101119cb6a27fb2258573bf35bb35929c0fd Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 12 Jan 2016 11:56:31 +0530 Subject: [PATCH] [fix] Currency symbol based on account/company currency, not based on Global Defaults --- .../accounts_receivable.py | 1 + .../report/balance_sheet/balance_sheet.py | 8 ++++-- .../accounts/report/cash_flow/cash_flow.py | 17 +++++++---- .../accounts/report/financial_statements.html | 2 +- .../accounts/report/financial_statements.py | 28 ++++++++++++++----- .../profit_and_loss_statement.py | 11 ++++---- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 89fc52c610..39fe5c4ba7 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -68,6 +68,7 @@ class ReceivablePayableReport(object): "label": _("Currency"), "fieldtype": "Data", "width": 100, + "hidden": 1 }, _("Remarks") + "::200" ] diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index 65d429c68f..0a2a9e308d 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -13,7 +13,8 @@ def execute(filters=None): asset = get_data(filters.company, "Asset", "Debit", period_list) liability = get_data(filters.company, "Liability", "Credit", period_list) equity = get_data(filters.company, "Equity", "Credit", period_list) - provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, period_list) + provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, + period_list, filters.company) data = [] data.extend(asset or []) @@ -26,12 +27,13 @@ def execute(filters=None): return columns, data -def get_provisional_profit_loss(asset, liability, equity, period_list): +def get_provisional_profit_loss(asset, liability, equity, period_list, company): if asset and (liability or equity): provisional_profit_loss = { "account_name": "'" + _("Provisional Profit / Loss (Credit)") + "'", "account": None, - "warn_if_negative": True + "warn_if_negative": True, + "currency": frappe.db.get_value("Company", company, "default_currency") } has_value = False diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index f6bf370df8..1fda16a9fd 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -50,10 +50,12 @@ def execute(filters=None): # compute net profit / loss income = get_data(filters.company, "Income", "Credit", period_list, ignore_closing_entries=True) expense = get_data(filters.company, "Expense", "Debit", period_list, ignore_closing_entries=True) - net_profit_loss = get_net_profit_loss(income, expense, period_list) + net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company) data = [] + company_currency = frappe.db.get_value("Company", filters.company, "default_currency") + for cash_flow_account in cash_flow_accounts: section_data = [] @@ -79,14 +81,16 @@ def execute(filters=None): account_data.update({ "account_name": account['label'], "indent": 1, - "parent_account": cash_flow_account['section_header'] + "parent_account": cash_flow_account['section_header'], + "currency": company_currency }) data.append(account_data) section_data.append(account_data) - add_total_row_account(data, section_data, cash_flow_account['section_footer'], period_list) + add_total_row_account(data, section_data, cash_flow_account['section_footer'], + period_list, company_currency) - add_total_row_account(data, data, _("Net Change in Cash"), period_list) + add_total_row_account(data, data, _("Net Change in Cash"), period_list, company_currency) columns = get_columns(period_list) return columns, data @@ -118,10 +122,11 @@ def get_account_type_based_data(company, account_type, period_list): return data -def add_total_row_account(out, data, label, period_list): +def add_total_row_account(out, data, label, period_list, currency): total_row = { "account_name": "'" + _("{0}").format(label) + "'", - "account": None + "account": None, + "currency": currency } for row in data: diff --git a/erpnext/accounts/report/financial_statements.html b/erpnext/accounts/report/financial_statements.html index c0869445da..84cad1610d 100644 --- a/erpnext/accounts/report/financial_statements.html +++ b/erpnext/accounts/report/financial_statements.html @@ -45,7 +45,7 @@ {% var fieldname = report.columns[i].field; %} {% if (!is_null(row[fieldname])) { %} - {%= format_currency(row[fieldname]) %} + {%= format_currency(row[fieldname], row.currency) %} {% } %} {% } %} diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 5e3184d408..f15b7344fd 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -80,6 +80,8 @@ def get_data(company, root_type, balance_must_be, period_list, ignore_closing_en return None accounts, accounts_by_name = filter_accounts(accounts) + + company_currency = frappe.db.get_value("Company", company, "default_currency") gl_entries_by_account = {} for root in frappe.db.sql("""select lft, rgt from tabAccount @@ -90,10 +92,10 @@ def get_data(company, root_type, balance_must_be, period_list, ignore_closing_en calculate_values(accounts_by_name, gl_entries_by_account, period_list) accumulate_values_into_parents(accounts, accounts_by_name, period_list) - out = prepare_data(accounts, balance_must_be, period_list) + out = prepare_data(accounts, balance_must_be, period_list, company_currency) if out: - add_total_row(out, balance_must_be, period_list) + add_total_row(out, balance_must_be, period_list, company_currency) return out @@ -114,7 +116,7 @@ def accumulate_values_into_parents(accounts, accounts_by_name, period_list): accounts_by_name[d.parent_account][period.key] = accounts_by_name[d.parent_account].get(period.key, 0.0) + \ d.get(period.key, 0.0) -def prepare_data(accounts, balance_must_be, period_list): +def prepare_data(accounts, balance_must_be, period_list, company_currency): out = [] year_start_date = period_list[0]["year_start_date"].strftime("%Y-%m-%d") year_end_date = period_list[-1]["year_end_date"].strftime("%Y-%m-%d") @@ -128,7 +130,8 @@ def prepare_data(accounts, balance_must_be, period_list): "parent_account": d.parent_account, "indent": flt(d.indent), "from_date": year_start_date, - "to_date": year_end_date + "to_date": year_end_date, + "currency": company_currency } for period in period_list: if d.get(period.key): @@ -146,10 +149,11 @@ def prepare_data(accounts, balance_must_be, period_list): return out -def add_total_row(out, balance_must_be, period_list): +def add_total_row(out, balance_must_be, period_list, company_currency): total_row = { "account_name": "'" + _("Total ({0})").format(balance_must_be) + "'", - "account": None + "account": None, + "currency": company_currency } for row in out: @@ -241,7 +245,7 @@ def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, g return gl_entries_by_account -def get_columns(period_list): +def get_columns(period_list, company=None): columns = [{ "fieldname": "account", "label": _("Account"), @@ -249,11 +253,21 @@ def get_columns(period_list): "options": "Account", "width": 300 }] + if company: + columns.append({ + "fieldname": "currency", + "label": _("Currency"), + "fieldtype": "Link", + "options": "Currency", + "hidden": 1 + }) + for period in period_list: columns.append({ "fieldname": period.key, "label": period.label, "fieldtype": "Currency", + "options": "currency", "width": 150 }) diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index 0431eb6e92..d26a3fcf9f 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -9,10 +9,10 @@ from erpnext.accounts.report.financial_statements import (get_period_list, get_c def execute(filters=None): period_list = get_period_list(filters.fiscal_year, filters.periodicity) - + income = get_data(filters.company, "Income", "Credit", period_list, ignore_closing_entries=True) expense = get_data(filters.company, "Expense", "Debit", period_list, ignore_closing_entries=True) - net_profit_loss = get_net_profit_loss(income, expense, period_list) + net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company) data = [] data.extend(income or []) @@ -20,16 +20,17 @@ def execute(filters=None): if net_profit_loss: data.append(net_profit_loss) - columns = get_columns(period_list) + columns = get_columns(period_list, filters.company) return columns, data -def get_net_profit_loss(income, expense, period_list): +def get_net_profit_loss(income, expense, period_list, company): if income and expense: net_profit_loss = { "account_name": "'" + _("Net Profit / Loss") + "'", "account": None, - "warn_if_negative": True + "warn_if_negative": True, + "currency": frappe.db.get_value("Company", company, "default_currency") } for period in period_list: