2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: update modified after triggers

This commit is contained in:
Faris Ansari 2019-12-20 11:54:48 +05:30
parent 2205a212eb
commit 75184d43c3

View File

@ -224,11 +224,11 @@ module.exports = class BaseDocument extends Observable {
setStandardValues() {
// set standard values on server-side only
if (frappe.isServer) {
let now = new Date().toISOString();
if (!this.submitted) {
if (this.isSubmittable && this.submitted == null) {
this.submitted = 0;
}
let now = new Date().toISOString();
if (!this.owner) {
this.owner = frappe.session.user;
}
@ -237,9 +237,14 @@ module.exports = class BaseDocument extends Observable {
this.creation = now;
}
if (!this.modifiedBy) {
this.updateModified();
}
}
updateModified() {
if (frappe.isServer) {
let now = new Date().toISOString();
this.modifiedBy = frappe.session.user;
}
this.modified = now;
}
}
@ -465,7 +470,6 @@ module.exports = class BaseDocument extends Observable {
async commit() {
// re-run triggers
this.setStandardValues();
this.setKeywords();
this.setChildIdx();
await this.applyFormula();
@ -474,6 +478,7 @@ module.exports = class BaseDocument extends Observable {
async insert() {
await this.setName();
this.setStandardValues();
await this.commit();
await this.validateInsert();
await this.trigger('beforeInsert');
@ -501,6 +506,9 @@ module.exports = class BaseDocument extends Observable {
if (this.flags.submitAction) await this.trigger('beforeSubmit');
if (this.flags.revertAction) await this.trigger('beforeRevert');
// update modifiedBy and modified
this.updateModified();
const data = await frappe.db.update(this.doctype, this.getValidDict());
this.syncValues(data);