class DepositModel(db.Model): __tablename__ = 'deposit' depositId = db.Column(db.String(10), unique=True, primary_key=True) txnId = db.Column(db.String(100), unique=True, nullable=False) clientId = db.Column(db.String(10)) clientName = db.Column(db.String(100)) warehouseCode = db.Column(db.String(10)) warehouseName = db.Column(db.String(100)) commodityCode = db.Column(db.String(10)) commodityName = db.Column(db.String(100)) uomCode = db.Column(db.String(10)) packType = db.Column(db.String(100)) active = db.Column(db.String(10)) status = db.Column(db.String(20)) noOfBags = db.Column(db.Float(Precision='25,5')) quantity = db.Column(db.Float(Precision='25,5')) netQuantity = db.Column(db.Float(Precision='25,5')) currenyQty = db.Column(db.Float(Precision='25,5')) currentPacks = db.Column(db.Float(Precision='25,5')) depositDate = db.Column(db.DateTime(timezone=True), nullable=False) createdDate = db.Column(db.DateTime(timezone=True), nullable=False) modifiedDate = db.Column(db.DateTime(timezone=True), nullable=False) lastBilledDate = db.Column(db.DateTime(timezone=True), nullable=False) billingType = db.Column(db.String(10)) createdBy = db.Column(db.String(20)) modifiedBy = db.Column(db.String(20))
class IdGeneratorModel(db.Model): __tablename__ = 'idGenerator' idKey = db.Column(db.String(10), unique=True, primary_key=True) idValue = db.Column(db.Integer(100)) createdDate = db.Column(db.DateTime(timezone=True), nullable=False) modifiedDate = db.Column(db.DateTime(timezone=True), nullable=False)
class BillingModel(db.Model): __tablename__ = 'wh_bill_ledger' billingId = db.Column(db.String(10), unique=True, primary_key=True) depositId = db.Column(db.String(10)) warehouseCode = db.Column(db.String()) warehouseName = db.Column(db.String(100)) clientId = db.Column(db.String(10)) clientName = db.Column(db.String(100)) commodityCode = db.Column(db.String(10)) commodityName = db.Column(db.String(100)) uomCode = db.Column(db.String(10)) quantity = db.Column(db.Float(Precision='25,5')) noOfPacks = db.Column(db.Float(Precision='25,5')) startBilledDate = db.Column(db.DateTime(timezone=True), nullable=False) endBilledDate = db.Column(db.DateTime(timezone=True), nullable=False) dailyRate = db.Column(db.Float(Precision='10,5')) weeklyRate = db.Column(db.Float(Precision='10,5')) monthlyRate = db.Column(db.Float(Precision='10,5')) billRate = db.Column(db.Float(Precision='25,5')) taxComponent = db.Column(db.Float(Precision='25,5')) totalBill = db.Column(db.Float(Precision='25,5')) invoiceId = db.Column(db.String(10)) createdBy = db.Column(db.String(100)) createdTimeStamp = db.Column(db.DateTime(timezone=True), nullable=False) modifiedBy = db.Column(db.String(100)) modifiedTimeStamp = db.Column(db.DateTime(timezone=True), nullable=False)
class UserModel(db.Model): __tablename__ = 'users' userId = db.Column(db.String(10), unique=True, primary_key=True) userName = db.Column(db.String(100), unique=True, nullable=False) userPassword = db.Column(db.String(512), nullable=False) userFullName = db.Column(db.String(512)) userRole = db.Column(db.String(10)) userOrg = db.Column(db.String(20)) createdDate = db.Column(db.DateTime(timezone=True), nullable=False) modifiedDate = db.Column(db.DateTime(timezone=True), nullable=False) createdBy = db.Column(db.String(512)) modifiedBy = db.Column(db.String(512))
class OrgModel(db.Model): __tablename__ = 'withdrawal' organizationId = db.Column(db.String(10), unique=True, primary_key=True) organizationName = db.Column(db.String(100), nullable=False) organizationType = db.Column(db.String(512)) organizationAddress = db.Column(db.String(512)) organizationLocation = db.Column(db.String(512)) organizationCity = db.Column(db.String(512)) organizationZipCode = db.Column(db.String(512)) organizationState = db.Column(db.String(512)) organizationDate = db.Column(db.DateTime(timezone=True), nullable=False) createdDate = db.Column(db.DateTime(timezone=True), nullable=False) modifiedDate = db.Column(db.DateTime(timezone=True), nullable=False) createdBy = db.Column(db.String(512)) modifiedBy = db.Column(db.String(512))
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64)) phone_number = db.Column(db.String(64), unique=True, index=True, nullable=False) city = db.Column(db.String(64)) registration_date = db.Column(db.DateTime(), default=datetime.utcnow) pin = db.Column(db.String(128)) is_pin_confirmed = db.Column(db.Boolean(), default=False) account = db.Column(db.Integer, default=10) @property def password(self): raise AttributeError('password is not a readable attribute') @password.setter def password(self, password): self.pip = generate_password_hash(password) def verify_password(self, password): return check_password_hash(self.pip, password) def __repr__(self): return "User {}".format(self.name) def deposit(self, amount): self.account += amount def withdraw(self, amount): self.account -= amount
class Snippets(db.Model): __tablename__ = 'snippets' id = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True) name = db.Column(db.String(200), nullable=False, unique=True) public_flag = db.Column(db.Boolean, nullable=False) reference = db.Column(db.String(), nullable=False) description = db.Column(db.Text, nullable=False) preview = db.Column(db.Text, nullable=False) born_date = db.Column(db.DateTime()) children_files = db.relationship('Files', cascade='all, delete', backref='snippets') @classmethod def find_by_name(cls, snippet_name): return cls.query.filter_by(name=snippet_name).first() @classmethod def find_by_id(cls, snippet_id): return cls.query.filter_by(id=snippet_id).first()
class Domain(db.Model): id = db.Column(db.String(256), primary_key=True) session_id = db.Column(db.String(256), db.ForeignKey('session.id'), nullable=False) url = db.Column(db.Text) title = db.Column(db.Text) favicon = db.Column(db.Text) start_time = db.Column(db.DateTime()) end_time = db.Column(db.DateTime()) time = db.Column(db.Float()) def __init__(self, data): settings = Session.query.filter_by( id=data['session_id']).first().user.settings data['id'] = str(uuid.uuid4()) data['start_time'] = cvt_date(data['start_time']) data['end_time'] = cvt_date(data['end_time']) data['time'] = (data['end_time'] - data['start_time']).seconds blocked_sites = settings.blocked_sites.split(os.getenv('TOKEN_DECODER_SPLITTER')) if settings.blocked_sites != '' \ else [] if data['time'] < settings.min_time or any(data['url'].startswith(i) for i in blocked_sites): print(blocked_sites) return super().__init__(**data) try: db.session.add(self) db.session.commit() except Exception as e: print(e) def detail(self): data = self.__dict__.copy() del data['_sa_instance_state'] return data @staticmethod def get(domain_id): return Domain.query.filter_by(id=domain_id).first() @staticmethod def delete(domain_id): domain = Domain.get(domain_id) if domain: db.session.delete(domain) db.session.commit()
class Data_Update(db.Model): id = db.Column('update_id', db.Integer, primary_key = True) update_time = db.Column(db.DateTime(timezone=True), nullable=False) update = db.Column(db.Text) user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=True) def __init__(self, update): self.update_time = datetime.datetime.now() self.update = update
class Purchase(db.Model): __tablename__ = 'purchases' app_id = db.Column(db.String, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) until = db.Column(db.DateTime(timezone=True)) def save_to_db(self): db.session.add(self) db.session.commit() @classmethod def find_purchase(cls, user, app_id): return cls.query.filter_by(user_id=user, app_id=app_id).first()
class Car(db.Model): __tablename__ = 'cars' id = db.Column(db.Integer, primary_key=True) created = db.Column(db.DateTime(timezone=True), index=False, unique=False, default=func.now()) maker = db.Column(db.String(64), index=False, unique=True, nullable=False) model = db.Column(db.String(80), index=True, unique=True, nullable=False) fuel_type = db.Column(db.String(80), index=True, unique=True, nullable=False) transmission = db.Column(db.String(80), index=True, unique=True, nullable=False) description = db.Column(db.Text, index=False, unique=False, nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def save_to_db(self): db.session.add(self) db.session.commit() @classmethod def find_by_maker(cls, maker): return cls.query.filter_by(maker=maker) @classmethod def find_by_model(cls, model): return cls.query.filter_by(model=model) @classmethod def return_all(cls): def to_json(x): return {'maker': x.maker, 'model': x.model} return {'cars': list(map(lambda x: to_json(x), Car.query.all()))}
class AttendanceModel(db.Model): __tablename__ = 'std_attendance' p_id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime(), nullable=False) class_id = db.Column(db.Integer, db.ForeignKey('classes.p_id'), nullable=False) department_id = db.Column(db.Integer, db.ForeignKey('departments.p_id'), nullable=False) subject_id = db.Column(db.Integer, db.ForeignKey('subjects.p_id'), nullable=False) student_id = db.Column(db.Integer, db.ForeignKey('students.p_id'), nullable=False) status = db.Column(db.String(50), nullable=False) classes = db.relationship("ClassModel", backref=db.backref("atten_class", uselist=False)) departmentes = db.relationship("DepartmentModel", backref=db.backref("atten_class", uselist=False)) subjects = db.relationship("SubjectModel", backref=db.backref("atten_subject")) students = db.relationship("StudentModel", backref=db.backref("atten_student")) def save_to_db(self): db.session.add(self) db.session.commit() def db_to_delete(self): db.session.delete(self) db.session.commit() def db_to_commit(self): db.session.commit() #FOR CONVERT DATA INTO JSON FORMAT @staticmethod def to_json(data): date = data.date return { 'date': date.strftime("%Y-%m-%d"), 'class': data.class_id, 'department': data.department_id, 'subject': data.subject_id, 'student': data.student_id, 'status': data.status } @classmethod def find_by_date(cls, class_id, department_id, subject_id, date): return AttendanceModel.query.filter_by(class_id=class_id, department_id=department_id, subject_id=subject_id, date=date).first() @classmethod def find_student_by_reg(cls, student_id): return StudentModel.query.filter_by(student_id=student_id).first() @classmethod def return_all(cls, class_id, department_id, subject_id, date): print(date) return { 'attendance': list( map( lambda x: cls.to_json(x), AttendanceModel.query.filter_by( date=date, class_id=class_id, department_id=department_id, subject_id=subject_id).all())) }