Need documentation on filters field in REST API


#1

Hello,
I am trying to use the flectra REST API.
i got it to work but is now stuck in the use of filters.
The provided example using like operator seems to work:
[(‘name’, ‘like’, ‘XXX’)

i tried below odoo ‘in’ operator and it did not work:
[( ‘id’ , ‘in’ , ‘[32,31]’ )]

I need to know how to combine multiple conditions and what are the different supported operator.
Thanks


#2

Here is the query I’m writing now
appointments = self.env [‘lab.appointment’]. search ([(‘date’, ‘> =’, date_start_obj), (‘date’, ‘<=’, date_end_obj), (‘state’, ‘=’ , state)])
It is necessary to carefully monitor the type of data transferred to the request


#3

Thanks Obeh,
Do i assume that conditions will be connected using ‘and’ logical operator ?
Also do we have the ‘in’ operator which is useful instead of multiple ‘=’ operators.
for example
instead of (‘state’, ‘=’ , ‘1’),(‘state’, ‘=’ , ‘2’),(‘state’, ‘=’ , ‘3’)
you just say: (‘state’, ‘in’ , ‘[1 , 2, 3]’)
in this case the conditions are connected using ‘or’ logical operator, so we get rows for any of the states.
Does flectra have this ? and if not how can i do similar condition ?


#4

Yes, the in operator works. I have tested. This is regular SQL.


#5

Thanks,
Could you please share example here ?
also, how to have multiple conditions joined by ‘or’ vs ‘and’.

Regards,


#6

Depending on the selected parameters, I generate a SQL query string in the program.
Then I do a bust of the result
for example
docs = []

    if state:
        if laboratory_id:
            appointments = self.env['lab.appointment'].search([('date', '>=', date_start_obj),('date', '<=', date_end_obj),('state', '=', state),('laboratory_id', 'in', laboratory_id)])
        else:
            appointments = self.env['lab.appointment'].search([('date', '>=', date_start_obj),('date', '<=', date_end_obj),('state', '=', state)])
    else:
        if laboratory_id:
            appointments = self.env['lab.appointment'].search([('date', '>=', date_start_obj),('date', '<=', date_end_obj),('laboratory_id', 'in', laboratory_id)])
        else:
            appointments = self.env['lab.appointment'].search([('date', '>=', date_start_obj),('date', '<=', date_end_obj)])
        state = "All"
    i = 0
    for appointment in appointments:
        i = i + 1 # Position counter in report
        docs.append({
            'poz': i,
            'appointment': appointment.name,
            'patient': appointment.patient_id.display_name,
            'state': appointment.state,
            'laboratory_code': appointment.laboratory_code,
            'laboratory_id': appointment.laboratory_id.display_name,
            'appointment_date': appointment.date,
            'age': appointment.patient_id.age,
        })

    return {
        'doc_ids': data['ids'],
        'doc_model': data['model'],
        'date_start': date_start,
        'date_end': date_end,
        'state': state,
        'poz': i,
        'docs': docs,
    }

#7

Thanks a lot Obeh,
I discovered the issue.
I was using array(“id”,“in”,$idList)
the correct expression is array(array(“id”,“in”,$idList))

Regards,