Merge pull request #28786 from gbm001/virtual_custom_link_fields

fix: Allow cancellation/rename of doctypes linked by a virtual custom field
This commit is contained in:
Akhil Narang 2025-08-01 13:44:46 +05:30 committed by GitHub
commit 40e6241c1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -478,16 +478,15 @@ def get_link_fields(doctype: str) -> list[dict]:
.inner_join(dt)
.on(df.parent == dt.name)
.select(df.parent, df.fieldname, dt.issingle.as_("issingle"))
.where((df.options == doctype) & (df.fieldtype == "Link"))
.where(
(df.options == doctype)
& (df.fieldtype == "Link")
& (dt.is_virtual == 0)
& (df.is_virtual == 0)
)
)
if frappe.db.has_column("DocField", "is_virtual"):
standard_fields_query = standard_fields_query.where(df.is_virtual == 0)
virtual_doctypes = []
if frappe.db.has_column("DocType", "is_virtual"):
virtual_doctypes = frappe.get_all("DocType", {"is_virtual": 1}, pluck="name")
standard_fields_query = standard_fields_query.where(dt.is_virtual == 0)
virtual_doctypes = frappe.get_all("DocType", {"is_virtual": 1}, pluck="name")
standard_fields = standard_fields_query.run(as_dict=True)
@ -495,7 +494,7 @@ def get_link_fields(doctype: str) -> list[dict]:
custom_fields = (
frappe.qb.from_(cf)
.select(cf.dt.as_("parent"), cf.fieldname, cf_issingle)
.where((cf.options == doctype) & (cf.fieldtype == "Link"))
.where((cf.options == doctype) & (cf.fieldtype == "Link") & (cf.is_virtual == 0))
)
if virtual_doctypes:
custom_fields = custom_fields.where(cf.dt.notin(virtual_doctypes))