From 9e0a5a2ea1f7847e7bff83fb089aeb862e935082 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 24 Jan 2013 20:44:09 +0100 Subject: [PATCH] Added authorized overdraft. Closes #6. --- src/api/controller/accounts.py | 5 +- src/api/model/accounts.py | 4 +- src/html/index.html | 10 ++- src/html/js/entries.js | 62 +++++++++++-------- src/sql/install/01_init.sql | 27 +++++++- .../0.1-0.2/001_authorized_overdraft.sql | 2 + 6 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 src/sql/update/0.1-0.2/001_authorized_overdraft.sql diff --git a/src/api/controller/accounts.py b/src/api/controller/accounts.py index b59d1f4..3ac705d 100644 --- a/src/api/controller/accounts.py +++ b/src/api/controller/accounts.py @@ -19,6 +19,7 @@ def get_accounts(): query = session.query( Account.id.label("id"), 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") @@ -27,6 +28,7 @@ def get_accounts(): return json.dumps([{ "id": i.id, "name": i.name, + "authorized_overdraft": i.authorized_overdraft, "current": str(i.current), "pointed": str(i.pointed), "future": str(i.future) @@ -51,7 +53,7 @@ def add_account(): session = db.create_scoped_session() try: - account = Account(request.json['name']) + account = Account(request.json['name'], request.json['authorized_overdraft']) session.add(account) session.commit() @@ -70,6 +72,7 @@ def update_account(account_id): account = session.query(Account).filter(Account.id == account_id).first() account.name = request.json['name'] + account.authorized_overdraft = request.json['authorized_overdraft'] session.merge(account) session.commit() diff --git a/src/api/model/accounts.py b/src/api/model/accounts.py index f2b12d4..1fd87de 100644 --- a/src/api/model/accounts.py +++ b/src/api/model/accounts.py @@ -4,7 +4,9 @@ from app import db class Account(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(200), nullable = False) + authorized_overdraft = db.Column(db.Integer, nullable = True, default = 0) - def __init__(self, name): + def __init__(self, name, authorized_overdraft): self.name = name + self.authorized_overdraft = authorized_overdraft diff --git a/src/html/index.html b/src/html/index.html index b4fffda..016a7de 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -120,6 +120,10 @@
+ +
+ +
@@ -130,13 +134,13 @@