feat: dr/cr amounts in reporting_currency on account_closing_balance

This commit is contained in:
diptanilsaha
2025-08-22 19:34:34 +05:30
parent fab9c4d7df
commit 8dbbcf5ffb
2 changed files with 58 additions and 3 deletions

View File

@@ -11,6 +11,9 @@
"cost_center", "cost_center",
"debit", "debit",
"credit", "credit",
"reporting_currency_exchange_rate",
"debit_in_reporting_currency",
"credit_in_reporting_currency",
"account_currency", "account_currency",
"debit_in_account_currency", "debit_in_account_currency",
"credit_in_account_currency", "credit_in_account_currency",
@@ -124,12 +127,30 @@
"fieldname": "is_period_closing_voucher_entry", "fieldname": "is_period_closing_voucher_entry",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Is Period Closing Voucher Entry" "label": "Is Period Closing Voucher Entry"
},
{
"fieldname": "debit_in_reporting_currency",
"fieldtype": "Currency",
"label": "Debit Amount in Reporting Currency",
"options": "Company:company:reporting_currency"
},
{
"fieldname": "credit_in_reporting_currency",
"fieldtype": "Currency",
"label": "Credit Amount in Reporting Currency",
"options": "Company:company:reporting_currency"
},
{
"fieldname": "reporting_currency_exchange_rate",
"fieldtype": "Float",
"label": "Reporting Currency Exchange Rate",
"precision": "9"
} }
], ],
"icon": "fa fa-list", "icon": "fa fa-list",
"in_create": 1, "in_create": 1,
"links": [], "links": [],
"modified": "2024-03-27 13:05:56.710541", "modified": "2025-08-22 19:13:50.400404",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Account Closing Balance", "name": "Account Closing Balance",
@@ -158,7 +179,8 @@
"role": "Auditor" "role": "Auditor"
} }
], ],
"row_format": "Dynamic",
"sort_field": "creation", "sort_field": "creation",
"sort_order": "DESC", "sort_order": "DESC",
"states": [] "states": []
} }

View File

@@ -2,12 +2,15 @@
# For license information, please see license.txt # For license information, please see license.txt
import frappe import frappe
from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import cint, cstr from frappe.utils import cint, cstr, flt
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions, get_accounting_dimensions,
) )
from erpnext.exceptions import ReportingCurrencyExchangeNotFoundError
from erpnext.setup.utils import get_exchange_rate
class AccountClosingBalance(Document): class AccountClosingBalance(Document):
@@ -26,12 +29,15 @@ class AccountClosingBalance(Document):
cost_center: DF.Link | None cost_center: DF.Link | None
credit: DF.Currency credit: DF.Currency
credit_in_account_currency: DF.Currency credit_in_account_currency: DF.Currency
credit_in_reporting_currency: DF.Currency
debit: DF.Currency debit: DF.Currency
debit_in_account_currency: DF.Currency debit_in_account_currency: DF.Currency
debit_in_reporting_currency: DF.Currency
finance_book: DF.Link | None finance_book: DF.Link | None
is_period_closing_voucher_entry: DF.Check is_period_closing_voucher_entry: DF.Check
period_closing_voucher: DF.Link | None period_closing_voucher: DF.Link | None
project: DF.Link | None project: DF.Link | None
reporting_currency_exchange_rate: DF.Float
# end: auto-generated types # end: auto-generated types
pass pass
@@ -55,6 +61,7 @@ def make_closing_entries(closing_entries, voucher_name, company, closing_date):
"closing_date": closing_date, "closing_date": closing_date,
} }
) )
set_amount_in_reporting_currency(cle, company, closing_date)
cle.flags.ignore_permissions = True cle.flags.ignore_permissions = True
cle.flags.ignore_links = True cle.flags.ignore_links = True
cle.submit() cle.submit()
@@ -144,3 +151,29 @@ def get_previous_closing_entries(company, closing_date, accounting_dimensions):
entries = query.run(as_dict=1) entries = query.run(as_dict=1)
return entries return entries
def set_amount_in_reporting_currency(cle, company, closing_date):
default_currency, reporting_currency = frappe.get_cached_value(
"Company", company, ["default_currency", "reporting_currency"]
)
reporting_currency_exchange_rate = get_exchange_rate(default_currency, reporting_currency, closing_date)
if not reporting_currency_exchange_rate:
frappe.throw(
title=_("Reporting Currency Exchange Not Found"),
msg=_(
"Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually."
).format(default_currency, reporting_currency, closing_date),
exc=ReportingCurrencyExchangeNotFoundError,
)
debit_in_reporting_currency = flt(cle.get("debit", 0) * reporting_currency_exchange_rate)
credit_in_reporting_currency = flt(cle.get("credit", 0) * reporting_currency_exchange_rate)
cle.update(
{
"reporting_currency_exchange_rate": reporting_currency_exchange_rate,
"debit_in_reporting_currency": debit_in_reporting_currency,
"credit_in_reporting_currency": credit_in_reporting_currency,
}
)