accountant-ui/src/api/model/entries.py

31 lines
1.1 KiB
Python
Raw Normal View History

from app import app
from app import db
from api.model.accounts import Account
from sqlalchemy import func, desc
from sqlalchemy.orm import column_property
from sqlalchemy.sql import func, select
class Entry(db.Model):
id = db.Column(db.Integer, primary_key=True)
pointed = db.Column(db.Boolean, nullable = False, default = False)
operation_date = db.Column(db.Date, nullable = False)
label = db.Column(db.String(500), nullable = False)
value = db.Column(db.Numeric(15, 2), nullable = False)
account_id = db.Column(db.Integer, db.ForeignKey('account.id'))
account = db.relationship(Account, backref = db.backref('entry', lazy="Dynamic"))
category = db.Column(db.String(100), nullable = True)
sold = column_property(func.sum(value).over(order_by="operation_date, value desc, label desc"))
def __init__(self, pointed, label, value, account_id, operation_date = None, category = None):
self.pointed = pointed
self.operation_date = operation_date
self.label = label
self.value = value
self.account_id = account_id
self.category = category