fix: correct monthly sales history (backport #50056) (#50179)

fix: correct monthly sales history (#50056)

* fix: correct monthly sales history

* fix: correct monthly sales history calculation

* chore: remove unrelated file accidentally committed

---------


(cherry picked from commit f51ed30c23)

Co-authored-by: Ahmed AbuKhatwa <82771130+AhmedAbokhatwa@users.noreply.github.com>
Co-authored-by: AhmedAbukhatwa <Ahmedabukhatwa1@gmail.com>
This commit is contained in:
mergify[bot]
2025-10-21 11:06:02 +05:30
committed by GitHub
parent 1e9ffe351b
commit afc2d95736

View File

@@ -763,13 +763,11 @@ def update_company_current_month_sales(company):
def update_company_monthly_sales(company):
"""Cache past year monthly sales of every company based on sales invoices"""
import json
from frappe.utils.goal import get_monthly_results
filter_str = f"company = {frappe.db.escape(company)} and status != 'Draft' and docstatus=1"
filter_dict = {"company": company, "status": ["!=", "Draft"], "docstatus": 1}
month_to_value_dict = get_monthly_results(
"Sales Invoice", "base_grand_total", "posting_date", filter_str, "sum"
"Sales Invoice", "base_grand_total", "posting_date", filter_dict, "sum"
)
frappe.db.set_value("Company", company, "sales_monthly_history", json.dumps(month_to_value_dict))