83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
from datetime import datetime, timezone, timedelta
|
|
from itertools import product
|
|
from app.extensions import db
|
|
from sqlalchemy.exc import IntegrityError
|
|
from sqlalchemy.orm import relationship
|
|
from dateutil.relativedelta import relativedelta
|
|
from datetime import timedelta
|
|
import logging
|
|
from sqlalchemy import and_, or_, not_
|
|
from sqlalchemy.sql import func
|
|
import json
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class ProvisionActions(db.Model):
|
|
__tablename__ = 'provision_actions'
|
|
|
|
id = db.Column(
|
|
db.Integer,
|
|
primary_key=True,
|
|
autoincrement=True,
|
|
)
|
|
|
|
uid = db.Column(db.String(150), nullable=True)
|
|
member_id = db.Column(db.Integer, nullable=False)
|
|
product_uid = db.Column(db.String(100), nullable=False)
|
|
action = db.Column(db.String(100), nullable=False)
|
|
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
|
percent_completed = db.Column(db.Integer, nullable=False)
|
|
|
|
|
|
@classmethod
|
|
def get_provision_action_by_member_id(cls, member_id, limit):
|
|
provision_action = cls.query.all()
|
|
provision_action = cls.query.filter_by(member_id=member_id).limit(limit).all()
|
|
if not provision_action:
|
|
return None
|
|
return provision_action
|
|
|
|
@classmethod
|
|
def get_provision_action_by_product_uid(cls, product_uid,limit):
|
|
# provision_action = cls.query.all()
|
|
# provision_action = cls.query.filter_by(product_uid=product_uid).limit(limit).all()
|
|
provision_action = cls.query.filter_by(product_uid=str(product_uid)).limit(limit).all()
|
|
if not provision_action:
|
|
return None
|
|
return provision_action
|
|
|
|
|
|
@classmethod
|
|
def get_provision_action_calendar_member_id(cls, member_id, limit):
|
|
provision_action = cls.query.all()
|
|
provision_action = cls.query.filter_by(member_id=member_id).order_by(cls.id.desc()).limit(limit).all()
|
|
if not provision_action:
|
|
return None
|
|
return provision_action
|
|
|
|
# '''
|
|
# merms_panel=# select * from provision_actions limit 2;
|
|
# id | uid | member_id | product_uid | action | added
|
|
# ----+--------------------------------------+-----------+--------------------------------------+-------------------------------+----------------------------
|
|
# 1 | 8b7db9fb-1404-4505-9858-7f418a6ae416 | 1 | df5bc060-18e0-4546-ae9a-89f7436f7cff | Allocating Provisioning Ports | 2025-07-12 21:21:02.036093
|
|
# 2 | d0e0fe16-4e0f-4cdc-856e-d8cfeb6c673f | 1 | 58645ef9-e334-45e0-8ce1-8ec637a20c50 | Allocating Provisioning Ports | 2025-07-13 15:02:04.388589
|
|
# (2 rows)
|
|
#
|
|
# '''
|
|
|
|
def to_dict(self):
|
|
"""
|
|
Convert the Loan object to a dictionary format for JSON serialization.
|
|
"""
|
|
return {
|
|
'id': self.id,
|
|
'uid': self.uid,
|
|
'product_uid': self.product_uid,
|
|
'action': self.action,
|
|
'percent_completed': self.percent_completed,
|
|
'added': self.added,
|
|
}
|
|
|
|
def __repr__(self):
|
|
return f'<ProvisionActions {self.id}>'
|