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

Hi everyone,

I am new to Odoo development and need to know what is the difference between @api.model and @api.multi and if possible, also tell me when/where to use each of them?

Thank you in advance

Regards

Paulo    

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

Hi,


@api.multi :-

Self will be the current RecordSet without iteration. It is the default behavior:

@api.multi
def afun(self):
    len(self)


@api.model:-

This decorator will convert old API calls to decorated function to new API signature. It allows to be polite when migrating code.

@api.model
def afun(self):
    pass

Please see this link: https://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Great. Thank you very much @Cybrosys

Câu trả lời hay nhất

@api.multi :-

The decorator in default for methods from new api onwards, which the self contains a recordset. So operations should be done by iterating through the recordsets if it is a set.

eg:

@api.multi
def multi_method(self):
    """ """
    print self # [model(1,2,3,4)] or [model(1,)]

@api.model :-

The decorator used on methods where the contents are not relevant. No ids will get passed with such methods.

eg:

@api.model
def create(self, vals)
    """ """
    print self # recordset with no id



Ảnh đại diện
Huỷ bỏ
Tác giả

Great. Thank you very much @Hilar

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 22
31366
3
thg 10 23
9546
1
thg 9 23
3653
1
thg 5 23
2559
2
thg 4 23
3209