跳至內容
選單
此問題已被標幟
1 回覆
6698 瀏覽次數

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.

頭像
捨棄

Hope this will helps: https://goo.gl/4BkizH

最佳答案

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


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 24
861
2
3月 20
4777
0
3月 19
4100
1
2月 19
6141
1
2月 23
7829