mirror of
https://github.com/frappe/books.git
synced 2025-02-04 04:58:30 +00:00
fix: Run formula for child docs passing parentdoc
This commit is contained in:
parent
133c8880d4
commit
ab57eef2eb
@ -135,15 +135,19 @@ module.exports = class BaseDocument extends Observable {
|
||||
this[key] = [];
|
||||
}
|
||||
this[key].push(this._initChild(document, key));
|
||||
this._dirty = true;
|
||||
this.applyChange(key);
|
||||
}
|
||||
|
||||
_initChild(data, key) {
|
||||
if (data instanceof BaseDocument) {
|
||||
return data;
|
||||
} else {
|
||||
data.doctype = this.meta.getField(key).childtype;
|
||||
data.parent = this.name;
|
||||
data.parenttype = this.doctype;
|
||||
data.parentfield = key;
|
||||
data.parentdoc = this;
|
||||
|
||||
if (!data.idx) {
|
||||
data.idx = (this[key] || []).length;
|
||||
@ -301,10 +305,15 @@ module.exports = class BaseDocument extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
// parent
|
||||
// parent or child row
|
||||
for (let field of this.meta.getFormulaFields()) {
|
||||
if (shouldApplyFormula(field, doc)) {
|
||||
const val = await field.formula(doc);
|
||||
let val;
|
||||
if (this.meta.isChild) {
|
||||
val = await field.formula(doc, this.parentdoc);
|
||||
} else {
|
||||
val = await field.formula(doc);
|
||||
}
|
||||
if (val !== false && val !== undefined) {
|
||||
doc[field.fieldname] = val;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user