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"), "label": _("Currency"),
"fieldtype": "Data", "fieldtype": "Data",
"width": 100, "width": 100,
"hidden": 1
}, },
_("Remarks") + "::200" _("Remarks") + "::200"
] ]

View File

@ -13,7 +13,8 @@ def execute(filters=None):
asset = get_data(filters.company, "Asset", "Debit", period_list) asset = get_data(filters.company, "Asset", "Debit", period_list)
liability = get_data(filters.company, "Liability", "Credit", period_list) liability = get_data(filters.company, "Liability", "Credit", period_list)
equity = get_data(filters.company, "Equity", "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 = []
data.extend(asset or []) data.extend(asset or [])
@ -26,12 +27,13 @@ def execute(filters=None):
return columns, data 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): if asset and (liability or equity):
provisional_profit_loss = { provisional_profit_loss = {
"account_name": "'" + _("Provisional Profit / Loss (Credit)") + "'", "account_name": "'" + _("Provisional Profit / Loss (Credit)") + "'",
"account": None, "account": None,
"warn_if_negative": True "warn_if_negative": True,
"currency": frappe.db.get_value("Company", company, "default_currency")
} }
has_value = False has_value = False

View File

@ -50,10 +50,12 @@ def execute(filters=None):
# compute net profit / loss # compute net profit / loss
income = get_data(filters.company, "Income", "Credit", period_list, ignore_closing_entries=True) 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) 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 = []
company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
for cash_flow_account in cash_flow_accounts: for cash_flow_account in cash_flow_accounts:
section_data = [] section_data = []
@ -79,14 +81,16 @@ def execute(filters=None):
account_data.update({ account_data.update({
"account_name": account['label'], "account_name": account['label'],
"indent": 1, "indent": 1,
"parent_account": cash_flow_account['section_header'] "parent_account": cash_flow_account['section_header'],
"currency": company_currency
}) })
data.append(account_data) data.append(account_data)
section_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) columns = get_columns(period_list)
return columns, data return columns, data
@ -118,10 +122,11 @@ def get_account_type_based_data(company, account_type, period_list):
return data 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 = { total_row = {
"account_name": "'" + _("{0}").format(label) + "'", "account_name": "'" + _("{0}").format(label) + "'",
"account": None "account": None,
"currency": currency
} }
for row in data: for row in data:

View File

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

View File

@ -81,6 +81,8 @@ def get_data(company, root_type, balance_must_be, period_list, ignore_closing_en
accounts, accounts_by_name = filter_accounts(accounts) accounts, accounts_by_name = filter_accounts(accounts)
company_currency = frappe.db.get_value("Company", company, "default_currency")
gl_entries_by_account = {} gl_entries_by_account = {}
for root in frappe.db.sql("""select lft, rgt from tabAccount for root in frappe.db.sql("""select lft, rgt from tabAccount
where root_type=%s and ifnull(parent_account, '') = ''""", root_type, as_dict=1): where root_type=%s and ifnull(parent_account, '') = ''""", root_type, as_dict=1):
@ -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) calculate_values(accounts_by_name, gl_entries_by_account, period_list)
accumulate_values_into_parents(accounts, accounts_by_name, 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: if out:
add_total_row(out, balance_must_be, period_list) add_total_row(out, balance_must_be, period_list, company_currency)
return out 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) + \ 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) 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 = [] out = []
year_start_date = period_list[0]["year_start_date"].strftime("%Y-%m-%d") 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") 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, "parent_account": d.parent_account,
"indent": flt(d.indent), "indent": flt(d.indent),
"from_date": year_start_date, "from_date": year_start_date,
"to_date": year_end_date "to_date": year_end_date,
"currency": company_currency
} }
for period in period_list: for period in period_list:
if d.get(period.key): if d.get(period.key):
@ -146,10 +149,11 @@ def prepare_data(accounts, balance_must_be, period_list):
return out 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 = { total_row = {
"account_name": "'" + _("Total ({0})").format(balance_must_be) + "'", "account_name": "'" + _("Total ({0})").format(balance_must_be) + "'",
"account": None "account": None,
"currency": company_currency
} }
for row in out: 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 return gl_entries_by_account
def get_columns(period_list): def get_columns(period_list, company=None):
columns = [{ columns = [{
"fieldname": "account", "fieldname": "account",
"label": _("Account"), "label": _("Account"),
@ -249,11 +253,21 @@ def get_columns(period_list):
"options": "Account", "options": "Account",
"width": 300 "width": 300
}] }]
if company:
columns.append({
"fieldname": "currency",
"label": _("Currency"),
"fieldtype": "Link",
"options": "Currency",
"hidden": 1
})
for period in period_list: for period in period_list:
columns.append({ columns.append({
"fieldname": period.key, "fieldname": period.key,
"label": period.label, "label": period.label,
"fieldtype": "Currency", "fieldtype": "Currency",
"options": "currency",
"width": 150 "width": 150
}) })

View File

@ -12,7 +12,7 @@ def execute(filters=None):
income = get_data(filters.company, "Income", "Credit", period_list, ignore_closing_entries=True) 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) 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 = []
data.extend(income or []) data.extend(income or [])
@ -20,16 +20,17 @@ def execute(filters=None):
if net_profit_loss: if net_profit_loss:
data.append(net_profit_loss) data.append(net_profit_loss)
columns = get_columns(period_list) columns = get_columns(period_list, filters.company)
return columns, data 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: if income and expense:
net_profit_loss = { net_profit_loss = {
"account_name": "'" + _("Net Profit / Loss") + "'", "account_name": "'" + _("Net Profit / Loss") + "'",
"account": None, "account": None,
"warn_if_negative": True "warn_if_negative": True,
"currency": frappe.db.get_value("Company", company, "default_currency")
} }
for period in period_list: for period in period_list: