2
0
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:
Faris Ansari 2019-10-19 20:05:13 +05:30
parent 0b015f4d90
commit 133c8880d4

View File

@ -24,7 +24,10 @@ module.exports = class BaseDocument extends Observable {
setValues(data) {
for (let fieldname in data) {
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) {
this.append(fieldname, row);
}
@ -32,6 +35,13 @@ module.exports = class BaseDocument extends Observable {
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() {
@ -207,7 +217,7 @@ module.exports = class BaseDocument extends Observable {
syncValues(data) {
this.clearValues();
Object.assign(this, data);
this.setValues(data);
this._dirty = false;
this.trigger('change', {
doc: this