Merge pull request #16462 from resilient-tech/fix-get-all-children

fix: incorrect logic for `parenttype` parameter in `get_all_children`
This commit is contained in:
gavin 2022-03-31 14:44:30 +05:30 committed by GitHub
commit 457188802a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -848,16 +848,19 @@ class Document(BaseDocument):
frappe.CancelledLinkError)
def get_all_children(self, parenttype=None):
"""Returns all children documents from **Table** type field in a list."""
ret = []
for df in self.meta.get("fields", {"fieldtype": ['in', table_fields]}):
if parenttype:
if df.options==parenttype:
return self.get(df.fieldname)
"""Returns all children documents from **Table** type fields in a list."""
children = []
for df in self.meta.get_table_fields():
if parenttype and df.options != parenttype:
continue
value = self.get(df.fieldname)
if isinstance(value, list):
ret.extend(value)
return ret
children.extend(value)
return children
def run_method(self, method, *args, **kwargs):
"""run standard triggers, plus those in hooks"""