Odoo ORM Methods


The common ORM methods in Odoo are listed below :

1. create()

The create() method is used to create new records for the model. It accepts the set of dictionary values.

When you create a new record in odoo, when saved that record the base create is called.

Syntax: model.create(value)


create blog


2. write()

The write() method is used to update your records in the model. It accepts the set of dictionary values and updates the record with those values.

When you click on the Edit button in odoo default at that time the base write() method is called.

Syntax: model.write(value)


write blog


3. copy()

The copy() method is used to duplicate the record in your model. This is only a default argument.

copy = True

If you don’t want to duplicate your data then you have to write copy=False in your argument.

Syntax: model.copy(default=None)


COPY blog


4. search()

The search() method is used for searching the record on that model. It’s used in multiple ways ; just like search by id, search all the records of that model.

We can also give the limit by searching the element .

Syntax: model.search(arguments)

For Example: If you want to search all the record of that model then,

self.search([ ])

If you want to search particular record then ,

self.search([ (‘argument’),limit=2 ])

search blog


5. search_count ()

This method returns the number of records matching which we gave in the search_count() domain. It accepts the domain as an argument .

Syntax: model.search_count([ domain passed here ])


search count blog


6. Browse()

The browse() method is used to return a set of records for the IDs passed as the parameter in the model. The browse method accepts a set of IDs and returns the recordsets corresponding to those IDs. It takes a database id or a list of ids and returns a recordset.

Syntax: model.browse([pass here ids])

For Example:

browse blog


7. Unlink()

The unlink() method is used to delete or remove the records or record set from the model. This method does not take any arguments, it removes the current records which are active.

Syntax : model.unlink( no arguments )

Example :



8. ensure_one()

This method checks whether the record set holds a single record or not. Otherwise raise an exception. It also check that the current record is singleton.

This function makes sure that we get a single record not  multiple records.

Syntax: model.ensure_one()


ensureone BLOG

Posted in Odoo OAuth