Added Number Cards for Opportunities

This commit is contained in:
Jeremy Rangel
2025-06-19 23:40:03 -07:00
parent 0b4f0f4a45
commit f44b3e8605
19 changed files with 288 additions and 4 deletions

View File

@ -0,0 +1,22 @@
{
"creation": "2020-07-20 20:17:15.922486",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Opportunity",
"dynamic_filters_json": "[[\"Opportunity\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
"filters_json": "[[\"Opportunity\",\"status\",\"not in\",[\"Closed\",\"Lost\"],false]]",
"function": "Sum",
"method": "rangeldigital.rangel_digital.number_card.pipeline_value_(this_month).pipeline_value_(this_month).get_number_card_data",
"idx": 0,
"is_public": 1,
"is_standard": 1,
"label": "Pipeline Value (This Month)",
"modified": "2025-06-19 12:15:53.088837",
"modified_by": "Administrator",
"module": "CRM",
"name": "Pipeline Value (This Month)",
"owner": "Administrator",
"show_percentage_stats": 0,
"stats_time_interval": "",
"type": "Custom"
}

View File

@ -0,0 +1,37 @@
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={
"expected_closing": ["between", [first_day, last_day]],
"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)")
}