45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from datetime import datetime, timezone
|
|
from app.extensions import db
|
|
from app.models.charge import Charge
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
class CustomTemplates(db.Model):
|
|
__tablename__ = 'custom_templates'
|
|
|
|
id = db.Column(db.String, primary_key=True)
|
|
uid = db.Column(db.String, nullable=False)
|
|
custom_id = db.Column(db.String, nullable=False)
|
|
provision_name = db.Column(db.String, nullable=False)
|
|
added = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
@classmethod
|
|
def get_template_by_custom_id(cls, custom_id):
|
|
templates = cls.query.filter_by(custom_id=str(custom_id)).all()
|
|
|
|
if not templates:
|
|
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,
|
|
"uid": self.uid,
|
|
"custom_id": self.product_id,
|
|
"provision_name": self.name,
|
|
"added": self.added.isoformat() if self.added else None
|
|
}
|
|
|
|
def __repr__(self):
|
|
return f'<CustomTemplates {self.id}>'
|