Replace method to use get with range in paramters.
This commit is contained in:
parent
7b49cec047
commit
b983835023
@ -14,7 +14,9 @@
|
|||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
from flask import json, request
|
import dateutil.parser
|
||||||
|
|
||||||
|
from flask import json
|
||||||
from flask.ext.restful import Resource, fields, reqparse, marshal_with_field
|
from flask.ext.restful import Resource, fields, reqparse, marshal_with_field
|
||||||
|
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
@ -26,34 +28,10 @@ from .. import api, api_api
|
|||||||
|
|
||||||
from ..models.accounts import Account
|
from ..models.accounts import Account
|
||||||
from ..models.entries import Entry
|
from ..models.entries import Entry
|
||||||
from ..models.operations import Operation
|
|
||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
|
|
||||||
@api.route("/accounts/<account_id>/<year>/<month>/")
|
|
||||||
@auth.login_required
|
|
||||||
def get_account_status(account_id, year, month):
|
|
||||||
with session_scope() as session:
|
|
||||||
query = Operation.get_account_status(session, account_id, year, month)
|
|
||||||
|
|
||||||
if query.count() == 1:
|
|
||||||
result = query.one()
|
|
||||||
revenues = result.revenues
|
|
||||||
expenses = result.expenses
|
|
||||||
balance = result.balance
|
|
||||||
else:
|
|
||||||
revenues = 0.0
|
|
||||||
expenses = 0.0
|
|
||||||
balance = 0.0
|
|
||||||
|
|
||||||
return json.dumps({
|
|
||||||
"expenses": str(expenses),
|
|
||||||
"revenues": str(revenues),
|
|
||||||
"balance": str(balance)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@api.route("/accounts/<account_id>/months")
|
@api.route("/accounts/<account_id>/months")
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def get_months(account_id):
|
def get_months(account_id):
|
||||||
@ -67,12 +45,15 @@ def get_months(account_id):
|
|||||||
|
|
||||||
|
|
||||||
resource_fields = {
|
resource_fields = {
|
||||||
'id': fields.Integer,
|
'id': fields.Integer(default=None),
|
||||||
'name': fields.String,
|
'name': fields.String,
|
||||||
'authorized_overdraft': fields.Fixed(decimals=2),
|
'authorized_overdraft': fields.Fixed(decimals=2),
|
||||||
'current': fields.Float,
|
'current': fields.Fixed(decimals=2),
|
||||||
'pointed': fields.Float,
|
'pointed': fields.Fixed(decimals=2),
|
||||||
'future': fields.Float,
|
'future': fields.Fixed(decimals=2),
|
||||||
|
'expenses': fields.Fixed(decimals=2),
|
||||||
|
'revenues': fields.Fixed(decimals=2),
|
||||||
|
'balance': fields.Fixed(decimals=2),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,6 +61,12 @@ parser = reqparse.RequestParser()
|
|||||||
parser.add_argument('name', type=str, required=True)
|
parser.add_argument('name', type=str, required=True)
|
||||||
parser.add_argument('authorized_overdraft', type=float, required=True)
|
parser.add_argument('authorized_overdraft', type=float, required=True)
|
||||||
|
|
||||||
|
date_parser = reqparse.RequestParser()
|
||||||
|
date_parser.add_argument('begin',
|
||||||
|
type=lambda a: dateutil.parser.parse(a) if a else None)
|
||||||
|
date_parser.add_argument('end',
|
||||||
|
type=lambda a: dateutil.parser.parse(a) if a else None)
|
||||||
|
|
||||||
|
|
||||||
class AccountListResource(Resource):
|
class AccountListResource(Resource):
|
||||||
@session_aware
|
@session_aware
|
||||||
@ -124,8 +111,10 @@ class AccountResource(Resource):
|
|||||||
"""
|
"""
|
||||||
Get account.
|
Get account.
|
||||||
"""
|
"""
|
||||||
|
kwargs = date_parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return Account.get(session, account_id)
|
return Account.get(session, account_id, **kwargs)
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
return None, 404
|
return None, 404
|
||||||
|
|
||||||
|
@ -86,8 +86,15 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
|
|||||||
|
|
||||||
$scope.getAccountStatus = function(account, month) {
|
$scope.getAccountStatus = function(account, month) {
|
||||||
if(account != null && month != null) {
|
if(account != null && month != null) {
|
||||||
$http.get("/api/accounts/" + account.id + "/" + month.year + "/" + month.month).
|
// Note: Month is 0 indexed.
|
||||||
success($scope.getAccountStatus_success);
|
var begin = moment({year: month.year, month: month.month - 1, day: 1});
|
||||||
|
var end = begin.clone().endOf('month');
|
||||||
|
|
||||||
|
$http.get("/api/accounts/" + account.id,
|
||||||
|
{params: {
|
||||||
|
begin: begin.format('YYYY-MM-DD'),
|
||||||
|
end: end.format('YYYY-MM-DD')
|
||||||
|
}}).success($scope.getAccountStatus_success);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,6 +83,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% block footer %}{% endblock %}
|
{% block footer %}{% endblock %}
|
||||||
|
<script type="text/javascript" src="https://raw.githubusercontent.com/moment/moment/develop/min/moment.min.js"></script>
|
||||||
|
|
||||||
<!-- JQuery Javascript library -->
|
<!-- JQuery Javascript library -->
|
||||||
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
|
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user