From 3523b779aaa619d753c732148e884e5568086af8 Mon Sep 17 00:00:00 2001 From: Zarrar Date: Tue, 14 Aug 2018 16:28:14 +0530 Subject: [PATCH] rounding off fixes and conversion fix (#15140) --- .../doctype/sales_invoice/sales_invoice.py | 2 +- erpnext/accounts/general_ledger.py | 21 ++++++++++++++----- .../report/general_ledger/general_ledger.py | 14 ++----------- erpnext/accounts/report/utils.py | 13 ++++++------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 5d7e79b82346..d1ef3a69997e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -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, } diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 1a8965e2c66f..a661c03b35b3 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -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, @@ -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, diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index f1997971ec54..7e579ac4cce2 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -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 @@ -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'), '') diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py index d1995d2b7a22..e33bd832afb3 100644 --- a/erpnext/accounts/report/utils.py +++ b/erpnext/accounts/report/utils.py @@ -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( @@ -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 @@ -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'):