From 6545e5b94c449fbee5dc43ad0c8176f343047a3c Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Tue, 21 Oct 2025 12:26:56 -0400 Subject: [PATCH] fix filter --- app/api/services/office_dashboard.py | 19 ++++++++++++++++++- app/models/products_templates.py | 24 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/api/services/office_dashboard.py b/app/api/services/office_dashboard.py index 6f3b801..e2a928e 100644 --- a/app/api/services/office_dashboard.py +++ b/app/api/services/office_dashboard.py @@ -227,7 +227,22 @@ class OfficeDashboardService(BaseService): @staticmethod def get_office_product_templates(filters): - templates = ProductsTemplates.get_template_for_office(filters) + + # Extract filters + product_id = filters.get('product_id') + provision_name = filters.get('provision_name') + + # Extract pagination parameters + page = int(filters.get('page', 1)) + limit = int(filters.get('limit', 20)) + + # Ensure page and limit are valid + if page < 1: + page = 1 + if limit < 1 or limit > 100: + limit = 20 + + templates = ProductsTemplates.get_template_for_office(product_id, provision_name, page, limit) templates_data = [] if templates: for t in templates: @@ -236,10 +251,12 @@ class OfficeDashboardService(BaseService): 'uid': t.uid, 'product_id': t.product_id, 'provision_name': t.provision_name, + 'status': t.status, 'added': t.added.isoformat() if t.added else None, }) templates_result = { "templates": templates_data, + "product_options": [] } return templates_result diff --git a/app/models/products_templates.py b/app/models/products_templates.py index 535a7a7..653dd87 100644 --- a/app/models/products_templates.py +++ b/app/models/products_templates.py @@ -3,6 +3,10 @@ from app.extensions import db from app.models.charge import Charge from sqlalchemy.orm import relationship from sqlalchemy.sql import func +import logging + + +logger = logging.getLogger(__name__) class ProductsTemplates(db.Model): @@ -27,8 +31,24 @@ class ProductsTemplates(db.Model): return templates @classmethod - def get_template_for_office(cls, filters): - templates = cls.query.all() + def get_template_for_office(cls, product_id=None, provision_name=None, page=1, limit=20): + + query = cls.query + logger.info(f"Get Templates for Office Product") + + if product_id: + query = query.filter(cls.product_id == product_id) + + if provision_name: + query = query.filter(cls.provision_name == provision_name) + + # Order by created_at descending (newest first) + query = query.order_by(cls.added.desc()) + + # Get total count before pagination + total_count = query.count() + + templates = query.all() if not templates: raise ValueError(f"Templates not found")