cancelDoc<T extends FrappeDocument> method
Returns the cancelled document T
of a submitted document.
Throws NotASubmittedDocument if the doc's status is not FrappeDocStatus.Submitted.
Returns a failure, if the document is duplicated or doctype/docname don't exist.
Implementation
@override
Future<RequestResponse<T?>> cancelDoc<T extends FrappeDocument>(T doc) async {
EmptyDoctypeError.verify(doc.doctype);
EmptyDocNameError.verify(doc.name);
if (doc.docStatus != FrappeDocStatus.Submitted) {
throw NotASubmittedDocument();
}
final response = await Request.initiateRequest(
url: config.hostUrl,
method: HttpMethod.POST,
contentType: ContentTypeLiterals.APPLICATION_JSON,
data: <String, dynamic>{
'doctype': doc.doctype,
'name': doc.name,
'cmd': 'frappe.client.cancel'
});
if (response.isSuccess) {
if (response.data != null &&
response.data!.exc == null &&
response.data!.message is Map) {
doc = doc.fromJson(response.data!.message);
doc.isLocal = false;
doc.unsaved = false;
doc.rawResponse = response.data!.message;
addToLocals(doc);
return RequestResponse.success(doc, rawResponse: response.rawResponse);
}
}
response.isSuccess = false;
return RequestResponse.fail(handleError('cancel_doc', response.error));
}