Muhammad Sajid
Muhammad Sajid

Reputation: 117

How to compare only date part of Create Date in odoo ORM search method?

attendance_record = self.pool.get('hr.attendance').search(
    cr, uid, ['&', ('create_date', '=', workfromhome[0].create_date),
              ('employee_id', '=', workfromhome[0].emp_id.id)])

I want to compare only date part of create_date in search method.

Upvotes: 0

Views: 919

Answers (1)

Devangi Shinde
Devangi Shinde

Reputation: 141

@v10 Odoo Search Orm Method:

current_date = fields.Date('Current Date', default=date.today())


list_of_attendance= [ ] 
attendance_ids = self.env['hr.attendance'].search([])

if attendance_ids:
    for res in attendance_ids :
        attendance_create_date = res.create_date
        get_create_date = attendance_create_date.split(" ")
        if current_date == get_create_date[0]:
             list_of_attendance.append(res.id)
  • list_of_attendance will returns search attendance ids of create date which you want to compare only date part.

  • you cannot directly search date wise because create_date is Datetime Field.

Upvotes: 1

Related Questions