diff --git a/src/api/controller/accounts.py b/src/api/controller/accounts.py index 6691fe4..411483d 100644 --- a/src/api/controller/accounts.py +++ b/src/api/controller/accounts.py @@ -21,8 +21,8 @@ def get_accounts(): Account.name.label("name"), Account.authorized_overdraft.label("authorized_overdraft"), func.sum(Entry.value).label("future"), - func.sum(case([(Entry.operation_date != None, Entry.value,)], else_=cast(0, db.Numeric(15, 2)))).label("pointed"), - func.sum(case([(Entry.value_date < func.now(), Entry.value,)], else_=cast(0, db.Numeric(15, 2)))).label("current") + func.sum(case([(Entry.pointed, Entry.value,)], else_=cast(0, db.Numeric(15, 2)))).label("pointed"), + func.sum(case([(Entry.operation_date < func.now(), Entry.value,)], else_=cast(0, db.Numeric(15, 2)))).label("current") ).outerjoin(Entry).group_by(Account.id).order_by(Account.id) return json.dumps([{ @@ -39,8 +39,8 @@ def get_months(account_id): session = db.session query = session.query( - distinct(extract("year", Entry.value_date)).label("year"), - extract("month", Entry.value_date).label("month") + distinct(extract("year", Entry.operation_date)).label("year"), + extract("month", Entry.operation_date).label("month") ).filter(Entry.account_id == account_id).order_by("year", "month") return json.dumps([{ diff --git a/src/api/controller/entries.py b/src/api/controller/entries.py index f31c466..26981df 100644 --- a/src/api/controller/entries.py +++ b/src/api/controller/entries.py @@ -25,17 +25,16 @@ def get_entries(account_id, year, month): session.query(Entry) .filter(Entry.account_id == account_id) .order_by( - desc(Entry.value_date), desc(Entry.operation_date), Entry.value, Entry.label, ).subquery() - ).filter(func.date_trunc('month', Entry.value_date) == "%s-%s-01" % (year, month)) + ).filter(func.date_trunc('month', Entry.operation_date) == "%s-%s-01" % (year, month)) return json.dumps([{ "id": i.id, - "value_date": i.value_date.strftime("%Y-%m-%d"), - "operation_date": i.operation_date.strftime("%Y-%m-%d") if i.operation_date else None, + "pointed": i.pointed, + "operation_date": i.operation_date.strftime("%Y-%m-%d"), "label": i.label, "value": str(i.value), "category": i.category, @@ -50,8 +49,8 @@ def add_entry(): try: entry = Entry( - value_date = request.json['value_date'], operation_date = request.json['operation_date'], + pointed = request.json['pointed'], label = request.json['label'], value = request.json['value'], category = request.json['category'], @@ -74,8 +73,8 @@ def update_entry(entry_id): entry = session.query(Entry).filter(Entry.id == entry_id).first() entry.id = entry_id - entry.value_date = request.json['value_date'] entry.operation_date = request.json['operation_date'] + entry.pointed = request.json['pointed'] entry.label = request.json['label'] entry.value = request.json['value'] entry.category = request.json['category'] diff --git a/src/api/model/entries.py b/src/api/model/entries.py index 9a376c9..f19e622 100644 --- a/src/api/model/entries.py +++ b/src/api/model/entries.py @@ -9,8 +9,8 @@ from sqlalchemy.sql import func, select 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) + 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')) @@ -18,11 +18,11 @@ class Entry(db.Model): 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, value desc, label desc")) - pointedsold = column_property(func.sum(value).over(partition_by="operation_date is not null", order_by="value_date, operation_date, value desc, label desc")) + sold = column_property(func.sum(value).over(order_by="operation_date, value desc, label desc")) + pointedsold = column_property(func.sum(value).over(partition_by="pointed", order_by="operation_date, value desc, label desc")) - def __init__(self, value_date, label, value, account_id, operation_date = None, category = None): - self.value_date = value_date + 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 diff --git a/src/html/index.html b/src/html/index.html index ad36cd3..10e536a 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -84,7 +84,7 @@ Date de valeur - Date de l'op. + Libellé de l'opération Montant Solde @@ -179,8 +179,6 @@