Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6323 Lượt xem

hello 

what is api and super method and why and when  super method is call ?

what is the difference between @api.model and @api.model_create_multi?


thanks in advance


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

The API decorators were initially introduced in Odoo 9.0 to support both old and new frameworks. As of Odoo 10.0, the old API is no longer supported, but some decorators, such as @api.model, are still being used.

When writing a new method, if you don't use any decorator, then the method is executed on a recordset. In such methods, self is a recordset that can refer to an arbitrary number of database records (this includes empty recordsets), and the code will often loop over the records in self to do something on each individual record. 

The @api.model decorator is similar, but it's used on methods for which only the model is important, not the contents of the recordset, which is not acted upon by the method.  So when you see api.model decorator set to method that's mean it operates on the model level, and not on the record set level. The concept is similar to Python's @classmethod decorator.

The api.model_create_multiDecorate a method that takes a list of dictionaries and creates multiple records. The method may be called with either a single dict or a list of dicts:

record = model.create(vals)
records = model.create([vals, ...])
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 24
2183
1
thg 12 23
2591
2
thg 8 23
2287
1
thg 12 23
4028
1
thg 7 23
2880