diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 38b23a7..50146f0 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -18,11 +18,13 @@ import dateutil.parser from flask.ext.restful import Resource, fields, reqparse, marshal_with_field +from sqlalchemy import true from sqlalchemy.orm.exc import NoResultFound from accountant import session_aware from ..models.scheduled_operations import ScheduledOperation +from ..models.operations import Operation from .. import api_api @@ -113,9 +115,6 @@ class ScheduledOperationResource(Resource): """ Delete a scheduled operation. """ - - raise NotImplementedError("Must be fixed.") - try: scheduled_operation = ScheduledOperation.query( session @@ -125,9 +124,22 @@ class ScheduledOperationResource(Resource): except NoResultFound: return None, 404 + operations = scheduled_operation.operations.filter( + Operation.confirmed == true() + ).count() + + import ipdb; ipdb.set_trace() + + if operations: + return "There are still confirmed operations associated to this \ + scheduled operation.", 409 + + # Delete unconfirmed operations + operations = scheduled_operation.operations.delete() + session.delete(scheduled_operation) - return scheduled_operation + return None, 204 @session_aware @marshal_with_field(Object(resource_fields)) diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 0c49b79..94a31fb 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -86,6 +86,27 @@ accountantApp } }; + /* + * Delete a scheduled operation. + */ + $scope.delete = function(operation, $index) { + var id = operation.id; + + bootbox.confirm( + "Voulez-vous supprimer l'operation planifiée \"" + operation.label + "\" ?", + function(result) { + if(result) { + operation.$delete().then(function() { + notificationService.success("Operation #" + id + " deleted."); + + // Remove account from array. + $scope.operations.splice($index, 1); + }); + } + } + ); + }; + // Load operations on controller initialization. $scope.loadOperations($routeParams.accountId); }]); diff --git a/accountant/frontend/static/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html index f4e389d..a18d898 100644 --- a/accountant/frontend/static/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -124,14 +124,14 @@