refactor: Move children load db into separate method

Signed-off-by: Gavin D'souza <gavin.dsouza@switchup.de>
This commit is contained in:
Gavin D'souza 2024-10-17 19:17:07 +02:00
parent 60df96ce08
commit b1d96dd532
No known key found for this signature in database
GPG key ID: 5413A43FBD450A34

View file

@ -255,6 +255,15 @@ class Document(BaseDocument):
super().__init__(d)
self.flags.pop("ignore_children", None)
self.load_children_from_db()
# sometimes __setup__ can depend on child values, hence calling again at the end
if hasattr(self, "__setup__"):
self.__setup__()
return self
def load_children_from_db(self):
for df in self._get_table_fields():
# Make sure not to query the DB for a child table, if it is a virtual one.
# During frappe is installed, the property "is_virtual" is not available in tabDocType, so
@ -277,10 +286,6 @@ class Document(BaseDocument):
self.set(df.fieldname, children)
# sometimes __setup__ can depend on child values, hence calling again at the end
if hasattr(self, "__setup__"):
self.__setup__()
return self
def reload(self) -> "Self":