mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-17 05:45:11 +00:00
feat: gl entries with values in reporting_currency
This commit is contained in:
@@ -437,6 +437,7 @@ def set_gl_entries_by_account(
|
||||
ignore_closing_entries=False,
|
||||
ignore_opening_entries=False,
|
||||
group_by_account=False,
|
||||
ignore_reporting_currency=True,
|
||||
):
|
||||
"""Returns a dict like { "account": [gl entries], ... }"""
|
||||
gl_entries = []
|
||||
@@ -467,6 +468,7 @@ def set_gl_entries_by_account(
|
||||
ignore_closing_entries,
|
||||
last_period_closing_voucher[0].name,
|
||||
group_by_account=group_by_account,
|
||||
ignore_reporting_currency=ignore_reporting_currency,
|
||||
)
|
||||
from_date = add_days(last_period_closing_voucher[0].period_end_date, 1)
|
||||
ignore_opening_entries = True
|
||||
@@ -482,9 +484,10 @@ def set_gl_entries_by_account(
|
||||
ignore_closing_entries,
|
||||
ignore_opening_entries=ignore_opening_entries,
|
||||
group_by_account=group_by_account,
|
||||
ignore_reporting_currency=ignore_reporting_currency,
|
||||
)
|
||||
|
||||
if filters and filters.get("presentation_currency"):
|
||||
if filters and filters.get("presentation_currency") and ignore_reporting_currency:
|
||||
convert_to_presentation_currency(gl_entries, get_currency(filters))
|
||||
|
||||
for entry in gl_entries:
|
||||
@@ -505,6 +508,7 @@ def get_accounting_entries(
|
||||
period_closing_voucher=None,
|
||||
ignore_opening_entries=False,
|
||||
group_by_account=False,
|
||||
ignore_reporting_currency=True,
|
||||
):
|
||||
gl_entry = frappe.qb.DocType(doctype)
|
||||
query = (
|
||||
@@ -524,6 +528,16 @@ def get_accounting_entries(
|
||||
.where(gl_entry.company == filters.company)
|
||||
)
|
||||
|
||||
if not ignore_reporting_currency:
|
||||
query = query.select(
|
||||
gl_entry.debit_in_reporting_currency
|
||||
if not group_by_account
|
||||
else Sum(gl_entry.debit_in_reporting_currency).as_("debit_in_reporting_currency"),
|
||||
gl_entry.credit_in_reporting_currency
|
||||
if not group_by_account
|
||||
else Sum(gl_entry.credit_in_reporting_currency).as_("credit_in_reporting_currency"),
|
||||
)
|
||||
|
||||
ignore_is_opening = frappe.get_single_value("Accounts Settings", "ignore_is_opening_check_for_reporting")
|
||||
|
||||
if doctype == "GL Entry":
|
||||
|
||||
@@ -135,15 +135,21 @@ def get_data(filters):
|
||||
return data
|
||||
|
||||
|
||||
def get_opening_balances(filters, ignore_is_opening):
|
||||
balance_sheet_opening = get_rootwise_opening_balances(filters, "Balance Sheet", ignore_is_opening)
|
||||
pl_opening = get_rootwise_opening_balances(filters, "Profit and Loss", ignore_is_opening)
|
||||
def get_opening_balances(filters, ignore_is_opening, exchange_rate=None, ignore_reporting_currency=True):
|
||||
balance_sheet_opening = get_rootwise_opening_balances(
|
||||
filters, "Balance Sheet", ignore_is_opening, exchange_rate, ignore_reporting_currency
|
||||
)
|
||||
pl_opening = get_rootwise_opening_balances(
|
||||
filters, "Profit and Loss", ignore_is_opening, exchange_rate, ignore_reporting_currency
|
||||
)
|
||||
|
||||
balance_sheet_opening.update(pl_opening)
|
||||
return balance_sheet_opening
|
||||
|
||||
|
||||
def get_rootwise_opening_balances(filters, report_type, ignore_is_opening):
|
||||
def get_rootwise_opening_balances(
|
||||
filters, report_type, ignore_is_opening, exchange_rate=None, ignore_reporting_currency=True
|
||||
):
|
||||
gle = []
|
||||
|
||||
last_period_closing_voucher = ""
|
||||
@@ -168,6 +174,7 @@ def get_rootwise_opening_balances(filters, report_type, ignore_is_opening):
|
||||
accounting_dimensions,
|
||||
period_closing_voucher=last_period_closing_voucher[0].name,
|
||||
ignore_is_opening=ignore_is_opening,
|
||||
ignore_reporting_currency=ignore_reporting_currency,
|
||||
)
|
||||
|
||||
# Report getting generate from the mid of a fiscal year
|
||||
@@ -180,24 +187,41 @@ def get_rootwise_opening_balances(filters, report_type, ignore_is_opening):
|
||||
accounting_dimensions,
|
||||
start_date=start_date,
|
||||
ignore_is_opening=ignore_is_opening,
|
||||
ignore_reporting_currency=ignore_reporting_currency,
|
||||
)
|
||||
else:
|
||||
gle = get_opening_balance(
|
||||
"GL Entry", filters, report_type, accounting_dimensions, ignore_is_opening=ignore_is_opening
|
||||
"GL Entry",
|
||||
filters,
|
||||
report_type,
|
||||
accounting_dimensions,
|
||||
ignore_is_opening=ignore_is_opening,
|
||||
ignore_reporting_currency=ignore_reporting_currency,
|
||||
)
|
||||
|
||||
opening = frappe._dict()
|
||||
for d in gle:
|
||||
opening.setdefault(
|
||||
d.account,
|
||||
{
|
||||
"account": d.account,
|
||||
"opening_debit": 0.0,
|
||||
"opening_credit": 0.0,
|
||||
},
|
||||
)
|
||||
opening[d.account]["opening_debit"] += flt(d.debit)
|
||||
opening[d.account]["opening_credit"] += flt(d.credit)
|
||||
opening_dr_cr = {
|
||||
"account": d.account,
|
||||
"opening_debit": 0.0,
|
||||
"opening_credit": 0.0,
|
||||
}
|
||||
|
||||
opening.setdefault(d.account, opening_dr_cr)
|
||||
|
||||
if ignore_reporting_currency:
|
||||
opening[d.account]["opening_debit"] += flt(d.debit)
|
||||
opening[d.account]["opening_credit"] += flt(d.credit)
|
||||
|
||||
else:
|
||||
if d.get("report_type") == "Balance Sheet" and not (
|
||||
d.get("root_type") == "Equity" or d.get("account_type") == "Equity"
|
||||
):
|
||||
opening[d.account]["opening_debit"] += flt(d.debit) * flt(exchange_rate)
|
||||
opening[d.account]["opening_credit"] += flt(d.credit) * flt(exchange_rate)
|
||||
else:
|
||||
opening[d.account]["opening_debit"] += flt(d.debit_in_reporting_currency)
|
||||
opening[d.account]["opening_credit"] += flt(d.credit_in_reporting_currency)
|
||||
|
||||
return opening
|
||||
|
||||
@@ -210,6 +234,7 @@ def get_opening_balance(
|
||||
period_closing_voucher=None,
|
||||
start_date=None,
|
||||
ignore_is_opening=0,
|
||||
ignore_reporting_currency=True,
|
||||
):
|
||||
closing_balance = frappe.qb.DocType(doctype)
|
||||
accounts = frappe.db.get_all("Account", filters={"report_type": report_type}, pluck="name")
|
||||
@@ -228,6 +253,12 @@ def get_opening_balance(
|
||||
.groupby(closing_balance.account)
|
||||
)
|
||||
|
||||
if not ignore_reporting_currency:
|
||||
opening_balance = opening_balance.select(
|
||||
Sum(closing_balance.debit_in_reporting_currency).as_("debit_in_reporting_currency"),
|
||||
Sum(closing_balance.credit_in_reporting_currency).as_("credit_in_reporting_currency"),
|
||||
)
|
||||
|
||||
if period_closing_voucher:
|
||||
opening_balance = opening_balance.where(
|
||||
closing_balance.period_closing_voucher == period_closing_voucher
|
||||
@@ -315,13 +346,21 @@ def get_opening_balance(
|
||||
|
||||
gle = opening_balance.run(as_dict=1)
|
||||
|
||||
if filters and filters.get("presentation_currency"):
|
||||
if filters and filters.get("presentation_currency") and ignore_reporting_currency:
|
||||
convert_to_presentation_currency(gle, get_currency(filters))
|
||||
|
||||
return gle
|
||||
|
||||
|
||||
def calculate_values(accounts, gl_entries_by_account, opening_balances, show_net_values, ignore_is_opening=0):
|
||||
def calculate_values(
|
||||
accounts,
|
||||
gl_entries_by_account,
|
||||
opening_balances,
|
||||
show_net_values,
|
||||
ignore_is_opening=0,
|
||||
exchange_rate=None,
|
||||
ignore_reporting_currency=True,
|
||||
):
|
||||
init = {
|
||||
"opening_debit": 0.0,
|
||||
"opening_credit": 0.0,
|
||||
@@ -340,8 +379,18 @@ def calculate_values(accounts, gl_entries_by_account, opening_balances, show_net
|
||||
|
||||
for entry in gl_entries_by_account.get(d.name, []):
|
||||
if cstr(entry.is_opening) != "Yes" or ignore_is_opening:
|
||||
d["debit"] += flt(entry.debit)
|
||||
d["credit"] += flt(entry.credit)
|
||||
if ignore_reporting_currency:
|
||||
d["debit"] += flt(entry.debit)
|
||||
d["credit"] += flt(entry.credit)
|
||||
else:
|
||||
if d.report_type == "Balance Sheet" and not (
|
||||
d.root_type == "Equity" or d.account_type == "Equity"
|
||||
):
|
||||
d["debit"] += flt(entry.debit) * flt(exchange_rate)
|
||||
d["credit"] += flt(entry.credit) * flt(exchange_rate)
|
||||
else:
|
||||
d["debit"] += flt(entry.debit_in_reporting_currency)
|
||||
d["credit"] += flt(entry.credit_in_reporting_currency)
|
||||
|
||||
d["closing_debit"] = d["opening_debit"] + d["debit"]
|
||||
d["closing_credit"] = d["opening_credit"] + d["credit"]
|
||||
|
||||
Reference in New Issue
Block a user