Skip to content

Commit

Permalink
fix: accounts receivable fixes (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
fproldan authored Jan 10, 2024
1 parent 8467432 commit b51e5a3
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import OrderedDict

import frappe
from frappe import _, scrub
from frappe import _, qb, scrub
from frappe.utils import cint, cstr, flt, getdate, nowdate

from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
Expand Down Expand Up @@ -88,6 +88,9 @@ def get_data(self):
# Get return entries
self.get_return_entries()

# Get Exchange Rate Revaluations
self.get_exchange_rate_revaluations()

self.data = []
for gle in self.gl_entries:
self.update_voucher_balance(gle)
Expand Down Expand Up @@ -273,8 +276,10 @@ def build_data(self):
conversion_rate = get_exchange_rate("USD", vourcher_data[currency_field], nowdate(), exchange_type)
row.outstanding_original_currency = flt((row.outstanding / conversion_rate), self.currency_precision)

if (abs(row.outstanding) > 1.0/10 ** self.currency_precision) and \
(abs(row.outstanding_in_account_currency) > 1.0/10 ** self.currency_precision):
if (abs(row.outstanding) > 1.0/10 ** self.currency_precision) and (
(abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision)
or (row.voucher_no in self.err_journals)
):
# non-zero oustanding, we must consider this row

if self.is_invoice(row) and self.filters.based_on_payment_terms:
Expand Down Expand Up @@ -586,7 +591,9 @@ def get_return_entries(self):

def set_ageing(self, row):
if self.filters.ageing_based_on == "Due Date":
entry_date = row.due_date
# use posting date as a fallback for advances posted via journal and payment entry
# when ageing viewed by due date
entry_date = row.due_date or row.posting_date
elif self.filters.ageing_based_on == "Supplier Invoice Date":
entry_date = row.bill_date
else:
Expand Down Expand Up @@ -637,10 +644,10 @@ def get_gl_entries(self):

if self.filters.get(scrub(self.party_type)):
select_fields = "debit_in_account_currency as debit, credit_in_account_currency as credit"
doc_currency_fields = "debit as debit_in_account_currency, credit as credit_in_account_currency"
else:
select_fields = "debit, credit"

doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"
doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"

remarks = ", remarks" if self.filters.get("show_remarks") else ""

Expand Down Expand Up @@ -925,3 +932,17 @@ def get_chart_data(self):
},
"type": 'percentage'
}

def get_exchange_rate_revaluations(self):
je = qb.DocType("Journal Entry")
results = (
qb.from_(je)
.select(je.name)
.where(
(je.company == self.filters.company)
& (je.posting_date.lte(self.filters.report_date))
& (je.voucher_type == "Exchange Rate Revaluation")
)
.run()
)
self.err_journals = [x[0] for x in results] if results else []

0 comments on commit b51e5a3

Please sign in to comment.