Merge pull request #4606 from nabinhait/report_currency

[fix] Currency symbol based on account/company currency, not based on Global Defaults
This commit is contained in:
Rushabh Mehta 2016-01-12 12:12:43 +05:30
commit 4a3140102c
6 changed files with 45 additions and 22 deletions

View File

@ -68,6 +68,7 @@ class ReceivablePayableReport(object):
"label": _("Currency"),
"fieldtype": "Data",
"width": 100,
"hidden": 1
},
_("Remarks") + "::200"
]

View File

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

View File

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

View File

@ -45,7 +45,7 @@
<td class="text-right">
{% var fieldname = report.columns[i].field; %}
{% if (!is_null(row[fieldname])) { %}
{%= format_currency(row[fieldname]) %}
{%= format_currency(row[fieldname], row.currency) %}
{% } %}
</td>
{% } %}

View File

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

View File

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