Search code examples
odooodoo-14

Odoo - How to search by date


I want to search a list of object based on date field

reservations = self.env['rm.reservation'].search([
    ('check_in', '=', self.check_in)
])

But when I run the Odoo, I get a runtime error

ValueError: Invalid field rm.reservation.check_in in leaf ('check_in', '=', datetime.date(2021, 12, 20))

This is the check_in field declaration in the reservation model class

check_in = fields.Date(string='Check In', required=True,
                       default=lambda self: fields.date.today())

Solution

  • Sorry this is my fault, I should call

    reservations = self.env['rm.reservation.room.line'].search([
        ('check_in', '=', self.check_in)
    ])
    

    And this is solve the problem