2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 12:10:06 +00:00

fix: prevent error slipping because of asyncness

This commit is contained in:
18alantom 2021-11-08 19:35:37 +05:30
parent 1390651803
commit 3e833309db

View File

@ -608,11 +608,11 @@ module.exports = class BaseDocument extends Observable {
return this;
}
insertOrUpdate() {
async insertOrUpdate() {
if (this._notInserted) {
return this.insert();
return await this.insert();
} else {
return this.update();
return await this.update();
}
}
@ -622,14 +622,23 @@ module.exports = class BaseDocument extends Observable {
await this.trigger('afterDelete');
}
async submitOrRevert(isSubmit) {
const wasSubmitted = this.submitted;
this.submitted = isSubmit;
try {
await this.update();
} catch (e) {
this.submitted = wasSubmitted;
throw e;
}
}
async submit() {
this.submitted = 1;
this.update();
await this.submitOrRevert(1);
}
async revert() {
this.submitted = 0;
this.update();
await this.submitOrRevert(0);
}
async rename(newName) {