mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
Formula enhancements
- apply formula on server side only if the field is read only - skip applying formula if the value is already set
This commit is contained in:
parent
b96ea40b99
commit
fb4295a12b
@ -227,10 +227,12 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
// for each row
|
// for each row
|
||||||
for (let row of this[tablefield.fieldname]) {
|
for (let row of this[tablefield.fieldname]) {
|
||||||
for (let field of formulaFields) {
|
for (let field of formulaFields) {
|
||||||
|
if (shouldApplyFormula(field, row)) {
|
||||||
const val = await field.formula(row, doc);
|
const val = await field.formula(row, doc);
|
||||||
if (val !== false) {
|
if (val !== false && val !== undefined) {
|
||||||
row[field.fieldname] = val;
|
row[field.fieldname] = val;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,13 +240,28 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
|
|
||||||
// parent
|
// parent
|
||||||
for (let field of this.meta.getFormulaFields()) {
|
for (let field of this.meta.getFormulaFields()) {
|
||||||
|
if (shouldApplyFormula(field, doc)) {
|
||||||
const val = await field.formula(doc);
|
const val = await field.formula(doc);
|
||||||
if (val !== false) {
|
if (val !== false && val !== undefined) {
|
||||||
doc[field.fieldname] = val;
|
doc[field.fieldname] = val;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
function shouldApplyFormula (field, doc) {
|
||||||
|
if (frappe.isServer) {
|
||||||
|
if (field.readOnly) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (doc[field.fieldname] == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async commit() {
|
async commit() {
|
||||||
|
Loading…
Reference in New Issue
Block a user