From 43fe7cbcc2a2aec631ccae04e483f251a694147a Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 22 Oct 2026 17:09:41 +0530 Subject: [PATCH] fix: refresh company total monthly sales on daily and monthly frequency (cherry picked from commit 204a20037ca18890b133a732cf42035b3fe219ba) --- .../doctype/selling_settings/selling_settings.json | 2 +- erpnext/setup/doctype/company/company.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json index 5bef5bc55a2..36069eeef4b 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.json +++ b/erpnext/selling/doctype/selling_settings/selling_settings.json @@ -87,7 +87,7 @@ }, { "default": "Each Transaction", - "description": "How often should Project and Company be updated based on Sales Transactions?", + "description": "How often should Project and Company be updated based on Sales Transactions? Daily refreshes nightly; Monthly refreshes on the 1st of each month.", "fieldname": "sales_update_frequency", "fieldtype": "Select", "label": "Sales Update Frequency in Company and Project", diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index def7b2aa22c..d202806eb95 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -838,13 +838,26 @@ def update_transactions_annual_history(company, commit=False): def cache_companies_monthly_sales_history(): + refresh_total_monthly_sales = _should_refresh_total_monthly_sales() companies = [d["name"] for d in frappe.get_list("Company")] for company in companies: update_company_monthly_sales(company) update_transactions_annual_history(company) + if refresh_total_monthly_sales: + update_company_current_month_sales(company) + frappe.db.commit() +def _should_refresh_total_monthly_sales(): + # "Each Transaction" updates on submit; refresh the cached figure for the + # scheduled frequencies only ("Monthly" just on the 1st). + frequency = frappe.get_single_value("Selling Settings", "sales_update_frequency") + if frequency == "Monthly": + return frappe.utils.now_datetime().day == 1 + return frequency == "Daily" + + @frappe.whitelist() def get_children(doctype, parent=None, company=None, is_root=False): if parent is None or parent == "All Companies":