Skip to content

Commit

Permalink
refactor: done modifications in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagar8848 committed Jan 16, 2025
1 parent 3743bd7 commit 8e851d3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frappe/model/db_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,20 @@ def prepare_filter_condition(self, f):
):
if f.operator.lower() == "like" and frappe.conf.get("db_type") == "postgres":
f.operator = "ilike"
if "ifnull(" in column_name.lower():
if "ifnull(" in column_name.lower() and frappe.conf.get("db_type") == "postgres":
column_name = column_name.replace("ifnull", "coalesce",1)
condition = f"{column_name} {f.operator} {value}"
else:
if df and df.fieldtype not in ("Check", "Float", "Int", "Currency", "Percent"):
condition = f"coalesce({column_name}, {fallback}) {f.operator} {value}"
if frappe.conf.get("db_type") == "postgres":
condition = f"coalesce({column_name}, {fallback}) {f.operator} {value}"
else:
condition = f"ifnull({column_name}, {fallback}) {f.operator} {value}"
else:
condition = f"coalesce({column_name}, {fallback}) {f.operator} {value}"
if frappe.conf.get("db_type") == "postgres":
condition = f"coalesce({column_name}, {fallback}) {f.operator} {value}"
else:
condition = f"ifnull({column_name}, {fallback}) {f.operator} {value}"
return condition

def build_match_conditions(self, as_condition=True) -> str | list:
Expand Down

0 comments on commit 8e851d3

Please sign in to comment.