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

Use isNew() instead of _notInserted

This commit is contained in:
Faris Ansari 2018-11-10 00:37:14 +05:30
parent 7be8302bc2
commit 3e6b741556
5 changed files with 16 additions and 12 deletions

View File

@ -195,8 +195,8 @@ module.exports = class Database extends Observable {
}
triggerChange(doctype, name) {
this.trigger(`change:${doctype}`, { name: name }, 500);
this.trigger(`change`, { doctype: name, name: name }, 500);
this.trigger(`change:${doctype}`, { name }, 500);
this.trigger(`change`, { doctype, name }, 500);
}
async insert(doctype, doc) {

View File

@ -188,7 +188,7 @@ module.exports = class BaseDocument extends Observable {
}
async compareWithCurrentDoc() {
if (frappe.isServer && !this._notInserted) {
if (frappe.isServer && !this.isNew()) {
let currentDoc = await frappe.db.get(this.doctype, this.name);
// check for conflict
@ -347,4 +347,8 @@ module.exports = class BaseDocument extends Observable {
}
return _values[fieldname];
}
isNew() {
return this._notInserted;
}
};

View File

@ -56,7 +56,7 @@ export default {
try {
this.doc = await frappe.getDoc(this.doctype, this.name);
if (this.doc._notInserted && this.meta.fields.map(df => df.fieldname).includes('name')) {
if (this.doc.isNew() && this.meta.fields.map(df => df.fieldname).includes('name')) {
// For a user editable name field,
// it should be unset since it is autogenerated
this.doc.set('name', '');
@ -82,7 +82,7 @@ export default {
if (this.invalid) return;
try {
if (this.doc._notInserted) {
if (this.doc.isNew()) {
await this.doc.insert();
} else {
await this.doc.update();

View File

@ -46,19 +46,19 @@ export default {
this.showSubmit =
this.meta.isSubmittable
&& !this.isDirty
&& !this.doc._notInserted
&& !this.doc.isNew()
&& this.doc.submitted === 0;
this.showRevert =
this.meta.isSubmittable
&& !this.isDirty
&& !this.doc._notInserted
&& !this.doc.isNew()
&& this.doc.submitted === 1;
this.showNextAction = 1
this.showNextAction =
!this.doc._notInserted
!this.doc.isNew()
&& this.links.length;
this.showPrint =
@ -66,14 +66,14 @@ export default {
&& this.meta.print
this.showSave =
this.doc._notInserted ?
this.doc.isNew() ?
true :
this.meta.isSubmittable ?
(this.isDirty ? true : false) :
true;
this.disableSave =
this.doc._notInserted ? false : !this.isDirty;
this.doc.isNew() ? false : !this.isDirty;
}
},
computed: {
@ -83,7 +83,7 @@ export default {
title() {
const _ = this._;
if (this.doc._notInserted) {
if (this.doc.isNew()) {
return _('New {0}', _(this.doc.doctype));
}

View File

@ -58,7 +58,7 @@ export default {
return false;
}
if (fieldname === 'name' && !this.doc._notInserted) {
if (fieldname === 'name' && !this.doc.isNew()) {
return false;
}