Rename solds, into balances.

This commit is contained in:
Alexis Lahouze 2017-05-25 21:32:42 +02:00
parent 5b87a27667
commit 7b9302cee2
2 changed files with 21 additions and 19 deletions

View File

@ -53,22 +53,20 @@ class Account(db.Model):
Operation.account_id == self.id
).one()
def flow(self, begin, end):
"""Return the flow for a specific time period."""
def income(self, begin, end):
"""Return the income for a specific time period."""
query = db.session.query(
db.func.sum(
db.case(
[(db.func.sign(Operation.value) == -1, Operation.value)],
else_=0
)
Operation.value
).filter(
db.func.sign(Operation.value) == -1
).label("expenses"),
db.func.sum(
db.case(
[(db.func.sign(Operation.value) == 1, Operation.value)],
else_=0
)
Operation.value
).filter(
db.func.sign(Operation.value) == 1
).label("revenues"),
db.func.sum(Operation.value).label("balance")
db.func.sum(Operation.value).label("income")
).filter(
Operation.account_id == self.id,
)

View File

@ -65,7 +65,10 @@ category_model = ns.model('Category', {
description='Total amount of expenses for the category'),
'revenues': fields.Float(
readonly=True,
description='Total amount of revenues for the category')
description='Total amount of revenues for the category'),
'income': fields.Float(
readonly=True,
description='Total income for the category')
})
# OHLC model.
@ -238,24 +241,25 @@ class AccountResource(Resource):
return None, 204
@ns.route('/<int:account_id>/solds')
@ns.route('/<int:account_id>/balances')
@ns.doc(
security='apikey',
params={
'account_id': 'Id of the account to manage'
},
responses={
200: ('OK', solds_model),
200: ('OK', balances_model),
401: 'Unauthorized',
404: 'Account not found'
})
class SoldsResource(Resource):
"""Resource to expose solds."""
class BalancesResource(Resource):
"""Resource to expose current, pointed and future balances."""
@ns.marshal_with(solds_model)
@ns.marshal_with(balances_model)
@jwt_required
def get(self, account_id):
"""Get solds for a specific account and date range."""
"""Get current, pointed and future balances for a specific account and
date range."""
account = Account.query().get(account_id)
@ -296,7 +300,7 @@ class BalanceResource(Resource):
# Note: if we don't pass the code, the result is seen as a tuple and
# causes error on marshalling.
return account.flow(**data), 200
return account.income(**data), 200
@ns.route("/<int:account_id>/category")