mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
fix: Set unset fields as null in document
This commit is contained in:
parent
0b015f4d90
commit
133c8880d4
@ -24,7 +24,10 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
setValues(data) {
|
setValues(data) {
|
||||||
for (let fieldname in data) {
|
for (let fieldname in data) {
|
||||||
let value = data[fieldname];
|
let value = data[fieldname];
|
||||||
if (Array.isArray(value)) {
|
if (fieldname.startsWith('_')) {
|
||||||
|
// private property
|
||||||
|
this[fieldname] = value;
|
||||||
|
} else if (Array.isArray(value)) {
|
||||||
for (let row of value) {
|
for (let row of value) {
|
||||||
this.append(fieldname, row);
|
this.append(fieldname, row);
|
||||||
}
|
}
|
||||||
@ -32,6 +35,13 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
this[fieldname] = value;
|
this[fieldname] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// set unset fields as null
|
||||||
|
for (let field of this.meta.getValidFields()) {
|
||||||
|
// check for null or undefined
|
||||||
|
if (this[field.fieldname] == null) {
|
||||||
|
this[field.fieldname] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get meta() {
|
get meta() {
|
||||||
@ -207,7 +217,7 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
|
|
||||||
syncValues(data) {
|
syncValues(data) {
|
||||||
this.clearValues();
|
this.clearValues();
|
||||||
Object.assign(this, data);
|
this.setValues(data);
|
||||||
this._dirty = false;
|
this._dirty = false;
|
||||||
this.trigger('change', {
|
this.trigger('change', {
|
||||||
doc: this
|
doc: this
|
||||||
|
Loading…
Reference in New Issue
Block a user