From 9809d3e7f382f0ef1969d943583bdaed8770926c Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sat, 20 Sep 2025 21:35:07 -0400 Subject: [PATCH] office templates --- app/api/routes/routes.py | 24 ++++++++++++++++ app/api/services/office_dashboard.py | 41 +++++++++++++++++++++++++++- app/models/custom_templates.py | 9 ++++++ app/models/products_templates.py | 9 ++++++ 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 62f6f86..8d214bb 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -459,6 +459,30 @@ def get_product_office(): result = OfficeDashboardService.get_office_products(filters) return jsonify(result) +@api.route('/office/product-templates', methods=['GET']) +def get_product_templates(): + # Call the dashboard service + filters = { + 'product_id': request.args.get('product_id'), + 'provision_name': request.args.get('provision_name'), + 'page': request.args.get('page', 1), + 'limit': request.args.get('limit', 20) + } + result = OfficeDashboardService.get_office_product_templates(filters) + return jsonify(result) + +@api.route('/office/custom-templates', methods=['GET']) +def get_custom_templates(): + # Call the dashboard service + filters = { + 'custom_id': request.args.get('custom_id'), + 'provision_name': request.args.get('provision_name'), + 'page': request.args.get('page', 1), + 'limit': request.args.get('limit', 20) + } + result = OfficeDashboardService.get_office_custom_templates(filters) + return jsonify(result) + # ===================================================== @api.route('/web/contents', methods=['GET']) # @token_required diff --git a/app/api/services/office_dashboard.py b/app/api/services/office_dashboard.py index 35da461..6f37c23 100644 --- a/app/api/services/office_dashboard.py +++ b/app/api/services/office_dashboard.py @@ -4,7 +4,8 @@ from app.api.services.base_service import BaseService from sqlalchemy import func, desc from datetime import datetime, timedelta, timezone from app.extensions import db -from app.models import MembersProducts, Products, Members, ProductsDetails, ProductsDetails, ProvisionActions, Payments +from app.models import MembersProducts, Products, Payments, \ + ProductsTemplates, CustomTemplates class OfficeDashboardService(BaseService): @@ -145,3 +146,41 @@ class OfficeDashboardService(BaseService): } return products_result + + @staticmethod + def get_office_product_templates(filters): + templates = ProductsTemplates.get_template_for_office(filters) + templates_data = [] + if templates: + for t in templates: + templates_data.append({ + 'id': t.id, + 'uid': t.uid, + 'product_id': t.product_id, + 'provision_name': t.provision_name, + 'added': t.added.isoformat() if t.added else None, + }) + templates_result = { + "templates": templates_data, + } + + return templates_result + + @staticmethod + def get_office_custom_templates(filters): + templates = CustomTemplates.get_template_for_office(filters) + templates_data = [] + if templates: + for t in templates: + templates_data.append({ + 'id': t.id, + 'uid': t.uid, + 'custom_id': t.custom_id, + 'provision_name': t.provision_name, + 'added': t.added.isoformat() if t.added else None, + }) + templates_result = { + "templates": templates_data, + } + + return templates_result diff --git a/app/models/custom_templates.py b/app/models/custom_templates.py index 366dfd5..1a3fed8 100644 --- a/app/models/custom_templates.py +++ b/app/models/custom_templates.py @@ -22,6 +22,15 @@ class CustomTemplates(db.Model): raise ValueError(f"Templates with Custom ID {custom_id} not found") return templates + @classmethod + def get_custom_template_for_office(cls, filters): + templates = cls.query.all() + + if not templates: + raise ValueError(f"Templates not found") + return templates + + def to_dict(self): return { "id": self.id, diff --git a/app/models/products_templates.py b/app/models/products_templates.py index 9c7948f..20e9d61 100644 --- a/app/models/products_templates.py +++ b/app/models/products_templates.py @@ -25,6 +25,15 @@ class ProductsTemplates(db.Model): raise ValueError(f"Templates with Product ID {product_id} not found") return templates + @classmethod + def get_template_for_office(cls, filters): + templates = cls.query.all() + + if not templates: + raise ValueError(f"Templates not found") + return templates + + def to_dict(self): return { "id": self.id,