submitDoc<T extends FrappeDocument> method
Submit a submittable document.
If the doctype or document don't exist, returns failure.
Throws NotSubmittableDocError if the doctype is not submittable based on its meta.
Implementation
@override
Future<RequestResponse<T?>> submitDoc<T extends FrappeDocument>(T doc) async {
EmptyDoctypeError.verify(doc.doctype);
EmptyDocNameError.verify(doc.name);
final meta =
await getFrappeMetaController().getDocMeta(doctype: doc.doctype);
if (meta.isSuccess && !meta.data!.isSubmittable!) {
throw NotSubmittableDocError();
}
final response = await Request.initiateRequest(
url: config.hostUrl,
method: HttpMethod.POST,
contentType: ContentTypeLiterals.APPLICATION_JSON,
data: <String, dynamic>{
'doc': doc.toJson(),
'cmd': 'frappe.client.submit'
});
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(
'submit_doc',
response.error ??
ErrorDetail(
info: Information(
data: response.data,
rawResponse: response.rawResponse,
httpCode: response.httpCode))));
}