feat: add admin settings system and improve customer/pricing endpoints

Add centralized admin settings (company info, social links, quick calls,
sidebar visibility toggles, theme, logo upload) with singleton pattern
and full CRUD API. Add active/dedicated customer count endpoints for
dashboard stats. Fix automatic assignment route to use PUT instead of
GET. Refactor oil price endpoint to use schema serialization with null
safety.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 18:45:06 -05:00
parent 6d5f44db55
commit 3066754821
6 changed files with 233 additions and 13 deletions

View File

@@ -8,7 +8,8 @@ from app.common.decorators import login_required as common_login_required
from app.common.responses import error_response, success_response
logger = logging.getLogger(__name__)
from datetime import datetime
from datetime import datetime, timedelta
from sqlalchemy import func
from app.classes.cards import Card_Card
from app.classes.customer import \
Customer_Customer, \
@@ -18,6 +19,7 @@ from app.classes.customer import \
Customer_Tank_Inspection_schema,\
Customer_Tank_Inspection
from app.classes.service import Service_Parts
from app.classes.delivery import Delivery_Delivery
from app.classes.admin import Admin_Company
from app.classes.auto import Auto_Delivery,Auto_Delivery_schema
from app.classes.stats_customer import Stats_Customer
@@ -437,6 +439,38 @@ def customer_count():
return success_response({'count': get_customer})
@customer.route("/count/active", methods=["GET"])
@login_required
def customer_count_active():
"""
Count distinct customers who had a delivery within the past year.
"""
logger.info("GET /customer/count/active - Getting active past year count")
one_year_ago = datetime.utcnow().date() - timedelta(days=365)
count = (db.session
.query(func.count(func.distinct(Delivery_Delivery.customer_id)))
.filter(Delivery_Delivery.when_delivered >= one_year_ago)
.scalar())
return success_response({'count': count or 0})
@customer.route("/count/dedicated", methods=["GET"])
@login_required
def customer_count_dedicated():
"""
Count distinct customers with more than one finalized delivery.
"""
logger.info("GET /customer/count/dedicated - Getting dedicated customer count")
subquery = (db.session
.query(Delivery_Delivery.customer_id)
.filter(Delivery_Delivery.delivery_status == 10)
.group_by(Delivery_Delivery.customer_id)
.having(func.count(Delivery_Delivery.id) > 1)
.subquery())
count = db.session.query(func.count()).select_from(subquery).scalar()
return success_response({'count': count or 0})
@customer.route("/automatic/status/<int:customer_id>", methods=["GET"])
@login_required
def customer_automatic_status(customer_id):
@@ -475,7 +509,7 @@ def get_all_automatic_deliveries():
@customer.route("/automatic/assign/<int:customer_id>", methods=["GET"])
@customer.route("/automatic/assign/<int:customer_id>", methods=["PUT"])
@login_required
def customer_automatic_assignment(customer_id):
"""