Hi,
Can anyone please tell me what happens in create, write and unlink functions and also when will these functions get called?
Also please tell me the difference between search and browse methods.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi,
Can anyone please tell me what happens in create, write and unlink functions and also when will these functions get called?
Also please tell me the difference between search and browse methods.
Hello Sameer,
I am very happy to expain these things.
create(self, values)
Takes a dictionary of field values, or a list of such dictionaries, and returns a recordset containing the records created
Creates new record. This method is invoked every time click on the 'New' button and the you save trough the 'Save' button.
values is a dictionary containing the values to store in the new record. The dictionary elements are in the form {'field_name': 'field_value',}.
Let say you have a Student model with name, fac_id and fac_no fields. You can create a new Student's record using the following call somewhere inside the Student class:
new_student_id = self.create({
'name': 'Joe Doe',
'fac_id': 15,
'fac_no': '161832'
})
write(self, values)
Takes a number of field values, writes them to all the records in its recordset. Does not return anything
Similar to create() but updates existing record(s). Which records to update is defined by the ids parameter. If you want to update the fac_id field of students with ids 166 and 299 you can do it in the following way:
self.write({'fac_id': 21})
browse(id):
Returns a recordset for the ids provided as parameter in the current environment.
Can take no ids, a single id or a sequence of ids.
Takes a database id or a list of ids and returns a recordset, useful when record ids are obtained from outside Odoo
>>> self.browse([7, 18, 12])
res.partner(7, 18, 12)
It is used when you have id of specific model and you want record based on it then it is very useful
unlink:
Deletes the records of the current set
search used to search in table based on some values domain that match to get record. In search you can pass value like name=ABCD. so if any record contains name as ABCD then you will get number of records but browse works diffrent then search. In browse you just pass id of record and odoo provides whole record.
If you really want to learn more just refer: https://goo.gl/X9po1m
Accept and upvote answer if helpful
Thanks and regards
Haresh Kansara
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
0
अग॰ 24
|
857 | ||
|
2
मार्च 20
|
4767 | ||
|
0
मार्च 19
|
4091 | ||
|
1
फ़र॰ 19
|
6129 | ||
filtered and mapped odoo16
Solved
|
|
1
फ़र॰ 23
|
7816 |
Hope this will helps: https://goo.gl/4BkizH