Implement scheduled operation deletion.
This commit is contained in:
parent
25885ff3ea
commit
8868dd18c2
@ -18,11 +18,13 @@ import dateutil.parser
|
|||||||
|
|
||||||
from flask.ext.restful import Resource, fields, reqparse, marshal_with_field
|
from flask.ext.restful import Resource, fields, reqparse, marshal_with_field
|
||||||
|
|
||||||
|
from sqlalchemy import true
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from accountant import session_aware
|
from accountant import session_aware
|
||||||
|
|
||||||
from ..models.scheduled_operations import ScheduledOperation
|
from ..models.scheduled_operations import ScheduledOperation
|
||||||
|
from ..models.operations import Operation
|
||||||
|
|
||||||
from .. import api_api
|
from .. import api_api
|
||||||
|
|
||||||
@ -113,9 +115,6 @@ class ScheduledOperationResource(Resource):
|
|||||||
"""
|
"""
|
||||||
Delete a scheduled operation.
|
Delete a scheduled operation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise NotImplementedError("Must be fixed.")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scheduled_operation = ScheduledOperation.query(
|
scheduled_operation = ScheduledOperation.query(
|
||||||
session
|
session
|
||||||
@ -125,9 +124,22 @@ class ScheduledOperationResource(Resource):
|
|||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
return None, 404
|
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)
|
session.delete(scheduled_operation)
|
||||||
|
|
||||||
return scheduled_operation
|
return None, 204
|
||||||
|
|
||||||
@session_aware
|
@session_aware
|
||||||
@marshal_with_field(Object(resource_fields))
|
@marshal_with_field(Object(resource_fields))
|
||||||
|
@ -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.
|
// Load operations on controller initialization.
|
||||||
$scope.loadOperations($routeParams.accountId);
|
$scope.loadOperations($routeParams.accountId);
|
||||||
}]);
|
}]);
|
||||||
|
@ -124,14 +124,14 @@
|
|||||||
<!-- Cancel edit. -->
|
<!-- Cancel edit. -->
|
||||||
<button type="button" class="btn btn-default"
|
<button type="button" class="btn btn-default"
|
||||||
ng-if="rowform.$visible"
|
ng-if="rowform.$visible"
|
||||||
ng-click="cancelEditOperation(operations, rowform)"
|
ng-click="cancelEditOperation(operation, rowform)"
|
||||||
title="Cancel">
|
title="Cancel">
|
||||||
<span class="fa fa-times"></span>
|
<span class="fa fa-times"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Remove operation. -->
|
<!-- Remove operation. -->
|
||||||
<button type="button" class="btn btn-default"
|
<button type="button" class="btn btn-default"
|
||||||
bs-modal="static/templates/operation_remove.html"
|
ng-click="delete(operation, $index)"
|
||||||
title="remove">
|
title="remove">
|
||||||
<span class="fa fa-trash"></span>
|
<span class="fa fa-trash"></span>
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user