In Odoo 8 ORM api, how to get results in reverse order with search ()?

I am trying to use search () to retrieve data from a table in an http controller.

x = obj.search(cr, uid, criteria, offset=0,limit=36,order=sortBy) 

It returns an array containing IDs of 36 elements sorted by sortBy , but always in ascending order. But how to do this using a decreasing order?

+6
source share
1 answer

Search

Searches for domain , returns a recordset of matching records. It can return a subset of matching records (offset and limit parameters) and be ordered (order parameter):

Syntax:

 search(args[, offset=0][, limit=None][, order=None][, count=False]) 

Options:

  • args is the search domain. Use an empty list to match all entries.
  • offset (int) - the number of results to ignore (default: none)
  • limit (int) - maximum number of returned records (default: all)
  • order (str) - sort string
  • count (bool) - if True, only counts and returns the number of matching records (default: False)

Returns . Returns records matching the search criteria to the limit.

Raise AccessError : if the user is trying to bypass the access rules for reading on the requested object.

You just need to search in descending order.

  sortBy = "field_name desc" x = obj.search(cr, uid, criteria, offset=0,limit=36,order=sortBy) ###Or you can define directly x = obj.search(cr, uid, criteria, offset=0,limit=36,order='field_name desc') 
+12
source

All Articles