refactor: move virtual child table check into get_table_fields
This commit is contained in:
parent
ff9995ec29
commit
76c04fef27
3 changed files with 10 additions and 9 deletions
|
|
@ -1983,10 +1983,8 @@ def get_lazy_controller(doctype):
|
|||
|
||||
# Dynamically construct a class that subclasses LazyDocument and original controller.
|
||||
lazy_controller = type(f"Lazy{original_controller.__name__}", (LazyDocument, original_controller), {})
|
||||
for fieldname, child_doctype in meta._table_doctypes.items():
|
||||
if meta.get_field(fieldname).is_virtual:
|
||||
continue
|
||||
setattr(lazy_controller, fieldname, LazyChildTable(fieldname, child_doctype))
|
||||
for df in meta.get_table_fields(include_virtual=False):
|
||||
setattr(lazy_controller, df.fieldname, LazyChildTable(df.fieldname, df.options))
|
||||
|
||||
lazy_controllers[doctype] = lazy_controller
|
||||
return lazy_controllers[doctype]
|
||||
|
|
|
|||
|
|
@ -221,8 +221,8 @@ class Meta(Document):
|
|||
|
||||
return set_only_once_fields
|
||||
|
||||
def get_table_fields(self):
|
||||
return self._table_fields
|
||||
def get_table_fields(self, include_virtual=True):
|
||||
return self._table_fields if include_virtual else self._non_virtual_table_fields
|
||||
|
||||
def get_global_search_fields(self):
|
||||
"""Return list of fields with `in_global_search` set and `name` if set."""
|
||||
|
|
@ -491,6 +491,11 @@ class Meta(Document):
|
|||
self._table_fields = DOCTYPE_TABLE_FIELDS
|
||||
else:
|
||||
self._table_fields = self.get("fields", {"fieldtype": ["in", table_fields]})
|
||||
self._non_virtual_table_fields = (
|
||||
[]
|
||||
if self.is_virtual
|
||||
else self.get("fields", {"fieldtype": ["in", table_fields], "is_virtual": 0})
|
||||
)
|
||||
|
||||
# table fieldname: doctype map
|
||||
self._table_doctypes = {field.fieldname: field.options for field in self._table_fields}
|
||||
|
|
|
|||
|
|
@ -416,9 +416,7 @@ def rename_doctype(doctype: str, old: str, new: str) -> None:
|
|||
|
||||
def update_child_docs(old: str, new: str, meta: "Meta") -> None:
|
||||
# update "parent"
|
||||
for df in meta.get_table_fields():
|
||||
if df.is_virtual or is_virtual_doctype(df.options):
|
||||
continue
|
||||
for df in meta.get_table_fields(include_virtual=False):
|
||||
(
|
||||
frappe.qb.update(df.options)
|
||||
.set("parent", new)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue