diff --git a/index.js b/index.js index 23a6684b..c1b60898 100644 --- a/index.js +++ b/index.js @@ -135,6 +135,14 @@ module.exports = { } }, + removeFromCache(doctype, name) { + try { + delete this.docs[doctype][name]; + } catch(e) { + console.warn(`Document ${doctype} ${name} does not exist`); + } + }, + isDirty(doctype, name) { return ( (this.docs && diff --git a/model/document.js b/model/document.js index d70ba791..400a9ea6 100644 --- a/model/document.js +++ b/model/document.js @@ -331,9 +331,14 @@ module.exports = class BaseDocument extends Observable { await this.commit(); await this.trigger('beforeInsert'); + let oldName = this.name; const data = await frappe.db.insert(this.doctype, this.getValidDict()); this.syncValues(data); + if (oldName !== this.name) { + frappe.removeFromCache(this.doctype, oldName); + } + await this.trigger('afterInsert'); await this.trigger('afterSave');