MiM
July 16, 2018, 9:24am
1
Hi all ,
i have fields of time and date and i want to select fields are not null.
when i write
frappe.get_list("Attendance", fields=["employee", "status"],\
filters=[["attendance_date", "=", date], \
["attend_time", "!=", ""], ["leave_time", "!=", ""]]
)
it gives me error
ValueError: (u'String does not contain a date:', u'')
any help please
MiM:
frappe.get_list(“Attendance”, fields=[“employee”, “status”],\ filters=[[“attendance_date”, “=”, date], \ [“attend_time”, “!=”, “”], [“leave_time”, “!=”, “”]] )
frappe.get_list("Attendance", fields=["employee", "status"],\
filters=[["attendance_date", "=", str(date)], \
["attend_time", "!=", ""], ["leave_time", "!=", ""]]
)
MiM
July 16, 2018, 9:31am
3
bhavikpatel7023:
date
what about these fileds
["attend_time", "!=", ""], ["leave_time", "!=", ""]
1 Like
MiM
July 16, 2018, 9:33am
5
it gives me
raise ValueError("String does not contain a date:", timestr)
ValueError: (u'String does not contain a date:', u'')
1 Like
MiM
July 16, 2018, 9:46am
7
if doctype EmployeeAttendanceTool
@frappe.whitelist()
def get_employees(date, department=None, branch=None, company=None, attendance_type =None,end_date=None):
attendance_not_marked = []
attendance_marked = []
filters = {"status": "Active"}
if department != "All":
filters["department"] = department
if branch != "All":
filters["branch"] = branch
if company != "All":
filters["company"] = company
# if attendance_type != "All":
# frappe.msgprint(attendance_type)
# filters["attendance_type"] = frappe.get_list("Attendance Period", filters=[["attendance_type","=",attendance_type]], fields=["name"])
employee_list = frappe.get_list("Employee", \
fields=["employee", "employee_name"], \
filters=filters, order_by="employee_name"
)
marked_employee = {}
for emp in frappe.get_list("Attendance", fields=["employee", "status"],\
filters=[["attendance_date", "=", date], \
["attend_time", "=", 'Null']] # <<<<<<<<<<<< this condition gives Error
):
marked_employee[emp['employee']] = emp['status']
for employee in employee_list:
employee['status'] = marked_employee.get(employee['employee'])
if employee['employee'] not in marked_employee:
attendance_not_marked.append(employee)
else:
attendance_marked.append(employee)
return {
"marked": attendance_marked,
"unmarked": attendance_not_marked
}
1 Like
frappe.get_list("Attendance", fields=["employee", "status"],\
filters=[["attendance_date", "=", str(date)], \
["attend_time", "not in",null], ["leave_time", "not in", null]]
)
MiM
July 16, 2018, 10:09am
9
["leave_time", "not in", null]
null here written as a variable
and is not defined
1 Like
Did this resolved your problem?
MiM
July 16, 2018, 11:50am
12
it does not work
but i solved it by adding new condition in
function prepare_filter_condition in file db_query.py
elif f.operator.lower() in ("is null", "is not null"):
self.ignore_ifnull = True
value = ""
and add value != “” in this condition
# put it inside double quotes
if isinstance(value, string_types) and not f.operator.lower() == 'between' and value !="":
value = '"{0}"'.format(frappe.db.escape(value, percent=False))
and
valid_operators = ("=", "!=", ">", "<", ">=", "<=", "like", "not like", "in", "not in", "between","is null","is not null")
if f.operator.lower() not in valid_operators:
frappe.throw(frappe._("Operator must be one of {0}").format(", ".join(valid_operators)))
2 Likes
FHenry
January 11, 2022, 2:25pm
13
frappe.get_list("Attendance", fields=["employee", "status"],\
filters=[["attendance_date", "in", null]]
)