Exemplo n.º 1
0
class Budget(db.Model):
    __tablename__ = "budgets"
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    amount = db.Column(db.Float, nullable=False)
    amount_used = db.Column(db.Float, nullable=False, default=0.00)
    category = db.Column(db.String(20), nullable=False)
    notes = db.Column(db.String(60), nullable=False)
    start_date = db.Column(db.Date, nullable=False, default=date.today())
    end_date = db.Column(db.Date, nullable=False)

    @classmethod
    def delete_expired(cls):
        expired_limit = 30
        expired_date = date.today() - timedelta(days=expired_limit)
        cls.query.filter(cls.end_date <= expired_date).delete()
        db.session.commit()

    # Hybrid Property is not displayed as a column
    @hybrid_property
    def status(self):
        if date.today() > self.end_date:
            return "EXPIRED"
        elif self.amount < self.amount_used:
            return "OVERBUDGET"
        return "ONGOING"

    @status.expression
    def status(cls):
        return case([(date.today() > cls.end_date, "EXPIRED"),
                     (cls.amount < cls.amount_used, "OVERBUDGET")],
                    else_="ONGOING")

    def __repr__(self):
        return f"Budget('{self.user_id}', '{self.id}', '{self.amount}', '{self.category}', '{self.start_date}', '{self.end_date}', '{self.status}')"
Exemplo n.º 2
0
class DailyRecords(db.Model):
    __tablename__ = "income&expense"
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    amount = db.Column(db.Float, nullable=False)
    type = db.Column(db.String, nullable=False)
    date = db.Column(db.Date, nullable=False, default=date.today())

    def __repr__(self):
        return f"('{self.user_id}', '{self.id}', '{self.amount}', '{self.type}', '{self.date}')"
Exemplo n.º 3
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}','{self.date_posted}')"
Exemplo n.º 4
0
class Transactions(db.Model):
    __tablename__ = "transactions"
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    amount = db.Column(db.Float, nullable=False)
    type = db.Column(db.String, nullable=False)
    category = db.Column(db.String(20), nullable=False)
    notes = db.Column(db.String(60), nullable=False)
    date = db.Column(db.Date, nullable=False, default=date.today())

    def __repr__(self):
        return f"Transactions('{self.user_id}', '{self.id}', '{self.amount}', '{self.type}', '{self.date}')"
Exemplo n.º 5
0
class InterestHistory(db.Model):
    __tablename__ = "interesthistory"
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    bank_name = db.Column(db.String, nullable=False, default='Some Bank')
    initial_capital = db.Column(db.Float, nullable=False)
    interest_rate = db.Column(db.Float, nullable=False)
    final_capital = db.Column(db.Float, nullable=False)
    type = db.Column(db.String, nullable=False)
    period = db.Column(db.Integer, nullable=False)

    def __repr__(self):
        return f"('{self.user_id}', '{self.bank_name}' '{self.initial_capital}', '{self.interest_rate}', '{self.final_capital}', '{self.type}', '{self.period}')"