'OR' in filter with multiple field

How to use OR operator with multiple field in filter

filters: {
“level_3”:“foo”,
OR
“level_2”:“bla”
}

Here I expect row with ‘level_3’ with ‘foo’ value or ‘level_2’ with ‘bla’ value

Anybody can help how to apply this kind of filter ?

1 Like

try this:

doc_list = frappe.get_all("Foo Bar",
	or_filters = [
		["level_3", "=", "foo"],
		["level_2", "=", "bla"]
	]
)
2 Likes

@revant_one is there something like

and_filters:

It seems no - while this finds lots of code instances:

frappe@ubuntu:~/frappe-bench$ find . -name “*.py” | xargs grep or_filters

None to be found for this:

frappe@ubuntu:~/frappe-bench$ find . -name “*.py” | xargs grep and_filters

filters: [
[“party”,"=", frm.doc.party]
[“status”,"=", 1]
],

I want to show invoice that is submitted for that party in custom reference, the above codes doesn’t do the job

filters property by default "and"s the values passed to it

eg.

filters=[
	["level_3", "=", "foo"],
	["level_2", "=", "bla"]
]

will be

(level_3='foo' AND level_2='bla') # in sql query

Best,
Suraj

3 Likes

Are you getting any errors while applying the filter ?

Since there’s a comma missing in your code.

It should be

filters: [
  [“party”, "=", frm.doc.party],
  [“status”, "=", 1]
],
1 Like