saveSubmitDoc<T extends FrappeDocument> method
Saves the document first, then submit, in a single db transaction.
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?>> saveSubmitDoc<T extends FrappeDocument>(
T doc) async {
await getFrappe().checkAppInstalled(features: ['saveSubmitDoc']);
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>{
'cmd': 'renovation_core.utils.doc.save_submit_doc',
'doc': doc
});
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('save_submit_doc', response.error));
}