Files
2025-06-19 23:40:03 -07:00

37 lines
1.1 KiB
Python

import frappe
from frappe import _
from datetime import datetime
from frappe.utils import get_first_day, get_last_day
@frappe.whitelist()
def get_number_card_data():
# Get the first and last day of the current month
today = datetime.today()
first_day = get_first_day(today).strftime('%Y-%m-%d')
last_day = get_last_day(today).strftime('%Y-%m-%d')
# Fetch open opportunities closing this month
opportunities = frappe.db.get_all(
"Opportunity",
filters={
"status": ["not in", ["Closed", "Lost"]]
},
fields=["name", "sales_stage", "base_opportunity_amount"]
)
total_theoretical_value = 0
for opp in opportunities:
probability = 0
if opp.sales_stage:
probability = frappe.db.get_value("Sales Stage", opp.sales_stage, "opportunity_probability") or 0
theoretical_value = (opp.base_opportunity_amount or 0) * (probability / 100)
total_theoretical_value += theoretical_value
return {
"value": round(total_theoretical_value, 2),
"fieldtype": "Currency",
"label": _("Theoretical Value (This Month)")
}