Skip to content

Commit

Permalink
rounding off fixes and conversion fix (#15140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlash65 authored and nabinhait committed Aug 14, 2018
1 parent 338dfcf commit 3523b77
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Expand Up @@ -865,7 +865,7 @@ def make_gle_for_rounding_adjustment(self, gl_entries):
self.get_gl_dict({
"account": round_off_account,
"against": self.customer,
"credit_in_account_currency": self.rounding_adjustment,
"credit_in_account_currency": self.base_rounding_adjustment,
"credit": self.base_rounding_adjustment,
"cost_center": round_off_cost_center,
}
Expand Down
21 changes: 16 additions & 5 deletions erpnext/accounts/general_ledger.py
Expand Up @@ -139,11 +139,21 @@ def round_off_debit_credit(gl_map):

def make_round_off_gle(gl_map, debit_credit_diff):
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(gl_map[0].company)

round_off_account_exists = False
round_off_gle = frappe._dict()
for k in ["voucher_type", "voucher_no", "company",
"posting_date", "remarks", "is_opening"]:
round_off_gle[k] = gl_map[0][k]
for d in gl_map:
if d.account == round_off_account:
round_off_gle = d
if d.debit_in_account_currency:
debit_credit_diff -= flt(d.debit_in_account_currency)
else:
debit_credit_diff += flt(d.credit_in_account_currency)
round_off_account_exists = True

if not round_off_gle:
for k in ["voucher_type", "voucher_no", "company",
"posting_date", "remarks", "is_opening"]:
round_off_gle[k] = gl_map[0][k]

round_off_gle.update({
"account": round_off_account,
Expand All @@ -158,7 +168,8 @@ def make_round_off_gle(gl_map, debit_credit_diff):
"against_voucher": None
})

gl_map.append(round_off_gle)
if not round_off_account_exists:
gl_map.append(round_off_gle)

def get_round_off_account_and_cost_center(company):
round_off_account, round_off_cost_center = frappe.get_cached_value('Company', company,
Expand Down
14 changes: 2 additions & 12 deletions erpnext/accounts/report/general_ledger/general_ledger.py
Expand Up @@ -89,12 +89,11 @@ def set_account_currency(filters):
account_currency = gle_currency
else:
account_currency = (None if filters.party_type in ["Employee", "Student", "Shareholder", "Member"] else
frappe.db.get_value(filters.party_type, filters.party, "default_currency"))
frappe.db.get_value(filters.party_type, filters.party[0], "default_currency"))

filters["account_currency"] = account_currency or filters.company_currency

if filters.account_currency != filters.company_currency:
filters["show_in_account_currency"] = 1
filters.presentation_currency = filters.account_currency

return filters

Expand Down Expand Up @@ -294,15 +293,6 @@ def get_result_as_list(data, filters):
balance = get_balance(d, balance, 'debit', 'credit')
d['balance'] = balance

if filters.get("show_in_account_currency"):
balance_in_account_currency = get_balance(d, balance_in_account_currency,
'debit_in_account_currency', 'credit_in_account_currency')
d['balance_in_account_currency'] = balance_in_account_currency
else:
d['debit_in_account_currency'] = d.get('debit', 0)
d['credit_in_account_currency'] = d.get('credit', 0)
d['balance_in_account_currency'] = d.get('balance')

d['account_currency'] = filters.account_currency
d['bill_no'] = inv_details.get(d.get('against_voucher'), '')

Expand Down
13 changes: 6 additions & 7 deletions erpnext/accounts/report/utils.py
Expand Up @@ -2,7 +2,7 @@
from erpnext import get_company_currency, get_default_company
from erpnext.setup.utils import get_exchange_rate
from erpnext.accounts.doctype.fiscal_year.fiscal_year import get_from_and_to_date
from frappe.utils import cint, get_datetime_str, formatdate
from frappe.utils import cint, get_datetime_str, formatdate, flt

__exchange_rates = {}
P_OR_L_ACCOUNTS = list(
Expand Down Expand Up @@ -49,7 +49,7 @@ def convert(value, from_, to, date):
:return: Result of converting `value`
"""
rate = get_rate_as_at(date, from_, to)
converted_value = value / (rate or 1)
converted_value = flt(value) / (rate or 1)
return converted_value


Expand Down Expand Up @@ -97,17 +97,16 @@ def convert_to_presentation_currency(gl_entries, currency_info):

for entry in gl_entries:
account = entry['account']
debit = cint(entry['debit'])
credit = cint(entry['credit'])
debit_in_account_currency = cint(entry['debit_in_account_currency'])
credit_in_account_currency = cint(entry['credit_in_account_currency'])
debit = flt(entry['debit'])
credit = flt(entry['credit'])
debit_in_account_currency = flt(entry['debit_in_account_currency'])
credit_in_account_currency = flt(entry['credit_in_account_currency'])
account_currency = entry['account_currency']

if account_currency != presentation_currency or (account_currency == presentation_currency and not is_p_or_l_account(account)):
value = debit or credit

date = currency_info['report_date'] if not is_p_or_l_account(account) else entry['posting_date']

converted_value = convert(value, presentation_currency, company_currency, date)

if entry.get('debit'):
Expand Down

0 comments on commit 3523b77

Please sign in to comment.