Rename solds, into balances.
This commit is contained in:
parent
5b87a27667
commit
7b9302cee2
@ -53,22 +53,20 @@ class Account(db.Model):
|
|||||||
Operation.account_id == self.id
|
Operation.account_id == self.id
|
||||||
).one()
|
).one()
|
||||||
|
|
||||||
def flow(self, begin, end):
|
def income(self, begin, end):
|
||||||
"""Return the flow for a specific time period."""
|
"""Return the income for a specific time period."""
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
db.func.sum(
|
db.func.sum(
|
||||||
db.case(
|
Operation.value
|
||||||
[(db.func.sign(Operation.value) == -1, Operation.value)],
|
).filter(
|
||||||
else_=0
|
db.func.sign(Operation.value) == -1
|
||||||
)
|
|
||||||
).label("expenses"),
|
).label("expenses"),
|
||||||
db.func.sum(
|
db.func.sum(
|
||||||
db.case(
|
Operation.value
|
||||||
[(db.func.sign(Operation.value) == 1, Operation.value)],
|
).filter(
|
||||||
else_=0
|
db.func.sign(Operation.value) == 1
|
||||||
)
|
|
||||||
).label("revenues"),
|
).label("revenues"),
|
||||||
db.func.sum(Operation.value).label("balance")
|
db.func.sum(Operation.value).label("income")
|
||||||
).filter(
|
).filter(
|
||||||
Operation.account_id == self.id,
|
Operation.account_id == self.id,
|
||||||
)
|
)
|
||||||
|
@ -65,7 +65,10 @@ category_model = ns.model('Category', {
|
|||||||
description='Total amount of expenses for the category'),
|
description='Total amount of expenses for the category'),
|
||||||
'revenues': fields.Float(
|
'revenues': fields.Float(
|
||||||
readonly=True,
|
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.
|
# OHLC model.
|
||||||
@ -238,24 +241,25 @@ class AccountResource(Resource):
|
|||||||
return None, 204
|
return None, 204
|
||||||
|
|
||||||
|
|
||||||
@ns.route('/<int:account_id>/solds')
|
@ns.route('/<int:account_id>/balances')
|
||||||
@ns.doc(
|
@ns.doc(
|
||||||
security='apikey',
|
security='apikey',
|
||||||
params={
|
params={
|
||||||
'account_id': 'Id of the account to manage'
|
'account_id': 'Id of the account to manage'
|
||||||
},
|
},
|
||||||
responses={
|
responses={
|
||||||
200: ('OK', solds_model),
|
200: ('OK', balances_model),
|
||||||
401: 'Unauthorized',
|
401: 'Unauthorized',
|
||||||
404: 'Account not found'
|
404: 'Account not found'
|
||||||
})
|
})
|
||||||
class SoldsResource(Resource):
|
class BalancesResource(Resource):
|
||||||
"""Resource to expose solds."""
|
"""Resource to expose current, pointed and future balances."""
|
||||||
|
|
||||||
@ns.marshal_with(solds_model)
|
@ns.marshal_with(balances_model)
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def get(self, account_id):
|
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)
|
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
|
# Note: if we don't pass the code, the result is seen as a tuple and
|
||||||
# causes error on marshalling.
|
# causes error on marshalling.
|
||||||
return account.flow(**data), 200
|
return account.income(**data), 200
|
||||||
|
|
||||||
|
|
||||||
@ns.route("/<int:account_id>/category")
|
@ns.route("/<int:account_id>/category")
|
||||||
|
Loading…
Reference in New Issue
Block a user