Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Date range for query (Frappe)

I want to create a filter for a frappe query that finds values which have a date between 2 other dates. Specifically, the Salary slip start_date and end_date should enclose the attendance_date.

doc_name = ##Some Salary Slip
document = frappe.get_doc('Salary Slip', doc_name)

leave_count = frappe.db.count('Attendance', filter={
    'employee': document.get('employee'),
    'status': 'Present',
    'late_entry': 1,
    'attendance_date': ['>=', document.get('start_date')],
    'attendance_date': ['<=', document.get('end_date')]})

Now this wont work as there are duplicate entries in the dictionary. So as per 1 and 2, I should be able to use lists as filters, but trying it like this

leave_count = frappe.db.count('Attendance', filters=[
             ['employee', '=', document.get('employee')],
             ['status', '=', 'Present'],
             ['late_entry', '=', 1],
             ['attendance_date', '>=', document.get('start_date')],
             ['attendance_date', '<=', document.get('end_date')]])

but it throws an error,

TypeError: can only concatenate str (not “list”) to str

And a quick peek at the code explains that currently only diciontaries are supported with the for loop that expects keys and not lists, and between is not option as that operator is autmatically converted to ‘=’ and that doesnt work.

So how do I do this?

**Cross post from stackoverflow as it didnt get any response **

I didn’t dive in the code, but since db.get_list was able to use between, perhaps you could just just use db.get_list and then do a count on the list that is returned?

That is what I am using currently, but it didnt seem that efficient so I just asked. But thanks for the reply.