From c3ed2bc04f89db1628082df3709160e4c1fdbea9 Mon Sep 17 00:00:00 2001 From: CoiledCoder Date: Mon, 25 Aug 2025 02:07:05 +0000 Subject: [PATCH 1/2] fix: correct typo in monthly auto exchange rate revaluation filter The "auto_create_exchange_rate_revaluation_monthly" function was using the wrong filter key `"Montly"` instead of `"Monthly"`. As a result, no companies configured for monthly ERR were being processed. --- erpnext/accounts/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 25baa783e4d..2b585f26688 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1818,7 +1818,7 @@ def auto_create_exchange_rate_revaluation_monthly() -> None: """ companies = frappe.db.get_all( "Company", - filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Montly"}, + filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Monthly"}, fields=["name", "submit_err_jv"], ) create_err_and_its_journals(companies) -- GitLab From 874a3b342cb538d985520cf79a19204446c8aad6 Mon Sep 17 00:00:00 2001 From: CoiledCoder Date: Mon, 25 Aug 2025 03:35:55 +0000 Subject: [PATCH 2/2] refactor: centralize exchange rate revaluation scheduling logic - Introduced a private helper `_auto_create_exchange_rate_revaluation_for(frequency)` - Removed duplicate logic across daily, weekly, and monthly ERR functions - Prevents future copy-paste bugs - Keeps existing behavior unchanged --- erpnext/accounts/utils.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 2b585f26688..a68c700b148 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1788,40 +1788,38 @@ def create_err_and_its_journals(companies: list | None = None) -> None: jv and frappe.get_doc("Journal Entry", jv).submit() -def auto_create_exchange_rate_revaluation_daily() -> None: +def _auto_create_exchange_rate_revaluation_for(frequency: str) -> None: """ - Executed by background job + Internal helper to avoid code duplication and typos. + Fetches companies by frequency and triggers ERR. """ companies = frappe.db.get_all( "Company", - filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Daily"}, + filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": frequency}, fields=["name", "submit_err_jv"], ) create_err_and_its_journals(companies) +def auto_create_exchange_rate_revaluation_daily() -> None: + """ + Executed by background job + """ + _auto_create_exchange_rate_revaluation_for("Daily") + + def auto_create_exchange_rate_revaluation_weekly() -> None: """ Executed by background job """ - companies = frappe.db.get_all( - "Company", - filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Weekly"}, - fields=["name", "submit_err_jv"], - ) - create_err_and_its_journals(companies) + _auto_create_exchange_rate_revaluation_for("Weekly") def auto_create_exchange_rate_revaluation_monthly() -> None: """ Executed by background job """ - companies = frappe.db.get_all( - "Company", - filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Monthly"}, - fields=["name", "submit_err_jv"], - ) - create_err_and_its_journals(companies) + _auto_create_exchange_rate_revaluation_for("Monthly") def get_payment_ledger_entries(gl_entries, cancel=0): -- GitLab