Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
22127 Представления

Right now when I started coding on Odoo v13 I found that Odoo has been removed @api.one.

What is the alternative of the @api.one in Odoo v13 ?


Аватар
Отменить
Лучший ответ

@api.one has been removed from v13.

Instead of using the decorator to loop over the function for each record in the recordset, you should loop inside your function using the standard for rec in self: code found throughout the rest of Odoo. 

If your function can only take a single record (for example if it returns an action based on a single record), self.ensure_one() should be called at the start, which will throw a record when a recordset is input.

Аватар
Отменить
Лучший ответ

Hi,

In Odoo13, all the decorators @api.multi, @api.returns, @api.one, @api.cr, @api.model_cr from the code. Now they are all multi-record by default. 

Thanks

Аватар
Отменить

What is that mean multi-record by default?

Лучший ответ

Well, looks like the official solution now is to loop through the records. Personally, I don't like this change. I think it's better to properly typify code, instead of adding imperceptible clutter like "for rec in self:" to the code.

But it's just my opinion.

So... may I suggest another alternative that is creating your own version of api.one in your modules code.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июл. 25
2765
0
мар. 25
1619
4
апр. 24
174530
0
дек. 23
2376
5
июл. 25
229083