Implement scheduled operation deletion.

This commit is contained in:
Alexis Lahouze 2015-08-21 00:03:18 +02:00
parent 25885ff3ea
commit 8868dd18c2
3 changed files with 39 additions and 6 deletions

View File

@ -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))

View File

@ -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);
}]);

View File

@ -124,14 +124,14 @@
<!-- Cancel edit. -->
<button type="button" class="btn btn-default"
ng-if="rowform.$visible"
ng-click="cancelEditOperation(operations, rowform)"
ng-click="cancelEditOperation(operation, rowform)"
title="Cancel">
<span class="fa fa-times"></span>
</button>
<!-- Remove operation. -->
<button type="button" class="btn btn-default"
bs-modal="static/templates/operation_remove.html"
ng-click="delete(operation, $index)"
title="remove">
<span class="fa fa-trash"></span>
</button>