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

fix: Remove doc from cache if name changes

This commit is contained in:
Faris Ansari 2019-10-19 19:59:41 +05:30
parent 94cc020f5a
commit f1823a71ab
2 changed files with 13 additions and 0 deletions

View File

@ -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) { isDirty(doctype, name) {
return ( return (
(this.docs && (this.docs &&

View File

@ -331,9 +331,14 @@ module.exports = class BaseDocument extends Observable {
await this.commit(); await this.commit();
await this.trigger('beforeInsert'); await this.trigger('beforeInsert');
let oldName = this.name;
const data = await frappe.db.insert(this.doctype, this.getValidDict()); const data = await frappe.db.insert(this.doctype, this.getValidDict());
this.syncValues(data); this.syncValues(data);
if (oldName !== this.name) {
frappe.removeFromCache(this.doctype, oldName);
}
await this.trigger('afterInsert'); await this.trigger('afterInsert');
await this.trigger('afterSave'); await this.trigger('afterSave');