Skip to Content
Menu
This question has been flagged
1 Reply
12154 Views

How to can read all record,only can write self record.

Avatar
Discard
Best Answer

Hi,
For reading the records you can use the orm methods in Odoo. Either you can use search, browse, read or readgroup for this.

Odoo ORM Methods:

  1. Odoo ORM Methods

      2. Odoo ORM Methods


See the Official Documentation:  ORM API

Model.browse([ids]) → records

Returns a recordset for the ids provided as parameter in the current environment.

self.browse([7, 18, 12])
res.partner(7, 18, 12)
Parameters
ids (int or list(int) or None) – id(s)
Returns
recordset
Model.search(args[, offset=0][, limit=None][, order=None][, count=False])

Searches for records based on the args search domain.

Parameters
  • argsA search domain. Use an empty list to match all records.
  • offset (int) – number of results to ignore (default: none)
  • limit (int) – maximum number of records to return (default: all)
  • order (str) – sort string
  • count (bool) – if True, only counts and returns the number of matching records (default: False)
Returns
at most limit records matching the search criteria
Raises
AccessError
  • if user tries to bypass access rules for read on the requested object.
Model.search_count(args) → int

Returns the number of records in the current model matching the provided domain.

Search for records that have a display name matching the given name pattern when compared with the given operator, while also matching the optional search domain (args).

This is used for example to provide suggestions based on a partial value for a relational field. Sometimes be seen as the inverse function of name_get(), but it is not guaranteed to be.

This method is equivalent to calling search() with a search domain based on display_name and then name_get() on the result of the search.

Parameters
  • name (str) – the name pattern to match
  • args (list) – optional search domain (see search() for syntax), specifying further restrictions
  • operator (str) – domain operator for matching name, such as 'like' or '='.
  • limit (int) – optional max number of records to return
Return type
Returns
list of pairs (id, text_repr) for all matching records.
Model.read([fields])

Reads the requested fields for the records in self, low-level/RPC method. In Python code, prefer browse().

Parameters
fields – list of field names to return (default is all fields)
Returns
a list of dictionaries mapping field names to their values, with one dictionary per record
Raises
AccessError – if user has no read rights on some of the given records
Model.read_group(domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True)

Get the list of records in list view grouped by the given groupby fields.

Parameters
  • domain (list) – A search domain. Use an empty list to match all records.
  • fields (list) – list of fields present in the list view specified on the object. Each element is either ‘field’ (field name, using the default aggregation), or ‘field:agg’ (aggregate field with aggregation function ‘agg’), or ‘name:agg(field)’ (aggregate field with ‘agg’ and return it as ‘name’). The possible aggregation functions are the ones provided by PostgreSQL (https://www.postgresql.org/docs/current/static/functions-aggregate.html) and ‘count_distinct’, with the expected meaning.
  • groupby (list) – list of groupby descriptions by which the records will be grouped. A groupby description is either a field (then it will be grouped by that field) or a string ‘field:groupby_function’. Right now, the only functions supported are ‘day’, ‘week’, ‘month’, ‘quarter’ or ‘year’, and they only make sense for date/datetime fields.
  • offset (int) – optional number of records to skip
  • limit (int) – optional max number of records to return
  • orderby (str) – optional order by specification, for overriding the natural sort ordering of the groups, see also search() (supported only for many2one fields currently)
  • lazy (bool) – if true, the results are only grouped by the first groupby and the remaining groupbys are put in the __context key. If false, all the groupbys are done in one call.
Returns

list of dictionaries(one dictionary for each record) containing:

  • the values of fields grouped by the fields in groupby argument
  • __domain: list of tuples specifying the search criteria
  • __context: dictionary with argument like groupby
Return type
[{‘field_name_1’: value, ..]
Raises
AccessError
  • if user has no read rights on the requested object
  • if user tries to bypass access rules for read on the requested object


Thanks

Avatar
Discard