mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
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
(cherry picked from commit 15040a362d)
This commit is contained in:
@@ -1743,40 +1743,38 @@ def create_err_and_its_journals(companies: list | None = None) -> None:
|
|||||||
jv and frappe.get_doc("Journal Entry", jv).submit()
|
jv and frappe.get_doc("Journal Entry", jv).submit()
|
||||||
|
|
||||||
|
|
||||||
|
def _auto_create_exchange_rate_revaluation_for(frequency: str) -> None:
|
||||||
|
"""
|
||||||
|
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": frequency},
|
||||||
|
fields=["name", "submit_err_jv"],
|
||||||
|
)
|
||||||
|
create_err_and_its_journals(companies)
|
||||||
|
|
||||||
|
|
||||||
def auto_create_exchange_rate_revaluation_daily() -> None:
|
def auto_create_exchange_rate_revaluation_daily() -> None:
|
||||||
"""
|
"""
|
||||||
Executed by background job
|
Executed by background job
|
||||||
"""
|
"""
|
||||||
companies = frappe.db.get_all(
|
_auto_create_exchange_rate_revaluation_for("Daily")
|
||||||
"Company",
|
|
||||||
filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Daily"},
|
|
||||||
fields=["name", "submit_err_jv"],
|
|
||||||
)
|
|
||||||
create_err_and_its_journals(companies)
|
|
||||||
|
|
||||||
|
|
||||||
def auto_create_exchange_rate_revaluation_weekly() -> None:
|
def auto_create_exchange_rate_revaluation_weekly() -> None:
|
||||||
"""
|
"""
|
||||||
Executed by background job
|
Executed by background job
|
||||||
"""
|
"""
|
||||||
companies = frappe.db.get_all(
|
_auto_create_exchange_rate_revaluation_for("Weekly")
|
||||||
"Company",
|
|
||||||
filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Weekly"},
|
|
||||||
fields=["name", "submit_err_jv"],
|
|
||||||
)
|
|
||||||
create_err_and_its_journals(companies)
|
|
||||||
|
|
||||||
|
|
||||||
def auto_create_exchange_rate_revaluation_monthly() -> None:
|
def auto_create_exchange_rate_revaluation_monthly() -> None:
|
||||||
"""
|
"""
|
||||||
Executed by background job
|
Executed by background job
|
||||||
"""
|
"""
|
||||||
companies = frappe.db.get_all(
|
_auto_create_exchange_rate_revaluation_for("Monthly")
|
||||||
"Company",
|
|
||||||
filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": "Monthly"},
|
|
||||||
fields=["name", "submit_err_jv"],
|
|
||||||
)
|
|
||||||
create_err_and_its_journals(companies)
|
|
||||||
|
|
||||||
|
|
||||||
def get_payment_ledger_entries(gl_entries, cancel=0):
|
def get_payment_ledger_entries(gl_entries, cancel=0):
|
||||||
|
|||||||
Reference in New Issue
Block a user