mirror of
https://github.com/frappe/books.git
synced 2025-01-24 15:48:25 +00:00
Use isNew() instead of _notInserted
This commit is contained in:
parent
7be8302bc2
commit
3e6b741556
@ -195,8 +195,8 @@ module.exports = class Database extends Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
triggerChange(doctype, name) {
|
triggerChange(doctype, name) {
|
||||||
this.trigger(`change:${doctype}`, { name: name }, 500);
|
this.trigger(`change:${doctype}`, { name }, 500);
|
||||||
this.trigger(`change`, { doctype: name, name: name }, 500);
|
this.trigger(`change`, { doctype, name }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
async insert(doctype, doc) {
|
async insert(doctype, doc) {
|
||||||
|
@ -188,7 +188,7 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async compareWithCurrentDoc() {
|
async compareWithCurrentDoc() {
|
||||||
if (frappe.isServer && !this._notInserted) {
|
if (frappe.isServer && !this.isNew()) {
|
||||||
let currentDoc = await frappe.db.get(this.doctype, this.name);
|
let currentDoc = await frappe.db.get(this.doctype, this.name);
|
||||||
|
|
||||||
// check for conflict
|
// check for conflict
|
||||||
@ -347,4 +347,8 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
}
|
}
|
||||||
return _values[fieldname];
|
return _values[fieldname];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isNew() {
|
||||||
|
return this._notInserted;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -56,7 +56,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
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,
|
// For a user editable name field,
|
||||||
// it should be unset since it is autogenerated
|
// it should be unset since it is autogenerated
|
||||||
this.doc.set('name', '');
|
this.doc.set('name', '');
|
||||||
@ -82,7 +82,7 @@ export default {
|
|||||||
if (this.invalid) return;
|
if (this.invalid) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.doc._notInserted) {
|
if (this.doc.isNew()) {
|
||||||
await this.doc.insert();
|
await this.doc.insert();
|
||||||
} else {
|
} else {
|
||||||
await this.doc.update();
|
await this.doc.update();
|
||||||
|
@ -46,19 +46,19 @@ export default {
|
|||||||
this.showSubmit =
|
this.showSubmit =
|
||||||
this.meta.isSubmittable
|
this.meta.isSubmittable
|
||||||
&& !this.isDirty
|
&& !this.isDirty
|
||||||
&& !this.doc._notInserted
|
&& !this.doc.isNew()
|
||||||
&& this.doc.submitted === 0;
|
&& this.doc.submitted === 0;
|
||||||
|
|
||||||
this.showRevert =
|
this.showRevert =
|
||||||
this.meta.isSubmittable
|
this.meta.isSubmittable
|
||||||
&& !this.isDirty
|
&& !this.isDirty
|
||||||
&& !this.doc._notInserted
|
&& !this.doc.isNew()
|
||||||
&& this.doc.submitted === 1;
|
&& this.doc.submitted === 1;
|
||||||
|
|
||||||
this.showNextAction = 1
|
this.showNextAction = 1
|
||||||
|
|
||||||
this.showNextAction =
|
this.showNextAction =
|
||||||
!this.doc._notInserted
|
!this.doc.isNew()
|
||||||
&& this.links.length;
|
&& this.links.length;
|
||||||
|
|
||||||
this.showPrint =
|
this.showPrint =
|
||||||
@ -66,14 +66,14 @@ export default {
|
|||||||
&& this.meta.print
|
&& this.meta.print
|
||||||
|
|
||||||
this.showSave =
|
this.showSave =
|
||||||
this.doc._notInserted ?
|
this.doc.isNew() ?
|
||||||
true :
|
true :
|
||||||
this.meta.isSubmittable ?
|
this.meta.isSubmittable ?
|
||||||
(this.isDirty ? true : false) :
|
(this.isDirty ? true : false) :
|
||||||
true;
|
true;
|
||||||
|
|
||||||
this.disableSave =
|
this.disableSave =
|
||||||
this.doc._notInserted ? false : !this.isDirty;
|
this.doc.isNew() ? false : !this.isDirty;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -83,7 +83,7 @@ export default {
|
|||||||
title() {
|
title() {
|
||||||
const _ = this._;
|
const _ = this._;
|
||||||
|
|
||||||
if (this.doc._notInserted) {
|
if (this.doc.isNew()) {
|
||||||
return _('New {0}', _(this.doc.doctype));
|
return _('New {0}', _(this.doc.doctype));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldname === 'name' && !this.doc._notInserted) {
|
if (fieldname === 'name' && !this.doc.isNew()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user