fix: adjust a few more queries

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang
2025-11-20 18:14:34 +05:30
parent 1cf9f903e5
commit 13f8bcd289
2 changed files with 9 additions and 4 deletions

View File

@@ -11,8 +11,8 @@ import frappe.defaults
from frappe import _, qb, throw
from frappe.desk.reportview import build_match_conditions
from frappe.model.meta import get_field_precision
from frappe.query_builder import AliasedQuery, Case, Criterion, Table
from frappe.query_builder.functions import Count, Max, Round, Sum
from frappe.query_builder import AliasedQuery, Case, Criterion, Field, Table
from frappe.query_builder.functions import Count, IfNull, Max, Round, Sum
from frappe.query_builder.utils import DocType
from frappe.utils import (
add_days,
@@ -1311,7 +1311,10 @@ def get_children(doctype, parent, company, is_root=False, include_disabled=False
if frappe.db.has_column(doctype, "disabled") and not include_disabled:
filters.append(["disabled", "=", False])
filters.append([f'ifnull(`{parent_fieldname}`,"")', "=", "" if is_root else parent])
if is_root:
filters.append(IfNull(Field(parent_fieldname), "") == "")
else:
filters.append([parent_fieldname, "=", parent])
if is_root:
fields += ["root_type", "report_type", "account_currency"] if doctype == "Account" else []

View File

@@ -409,7 +409,9 @@ def get_children(doctype, parent, task=None, project=None, is_root=False):
# via expand child
filters.append(["parent_task", "=", parent])
else:
filters.append(['ifnull(`parent_task`, "")', "=", ""])
from frappe.query_builder import Field, functions
filters.append(functions.IfNull(Field("parent_task"), "") == "")
if project:
filters.append(["project", "=", project])