Rewrote the application in Python/Flask/SQLAlchemy
This commit is contained in:
33
src/api/model/entries.py
Normal file
33
src/api/model/entries.py
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
class Entry(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
value_date = db.Column(db.Date, nullable = False)
|
||||
operation_date = db.Column(db.Date, nullable = True)
|
||||
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="value_date, operation_date, label desc, value desc"))
|
||||
pointedsold = column_property(func.sum(value).over(partition_by="operation_date is not null", order_by="value_date, operation_date, label desc, value desc"))
|
||||
|
||||
def __init__(self, value_date, label, value, account_id, operation_date = None, category = None):
|
||||
self.value_date = value_date
|
||||
self.operation_date = operation_date
|
||||
self.label = label
|
||||
self.value = value
|
||||
self.account_id = account_id
|
||||
self.category = category
|
||||
|
Reference in New Issue
Block a user