Skip to Content
Menu
This question has been flagged

Is anyone stumble over situation when in module you start put any @api decorator and it crashes odoo?

I have module with states. I'm trying to signed button function to change state. But when i writing any @api decorator
and restart server, reload web page, it pushes me to form of choosing database or shows continious messages about connection lost and retrieve.

When i comment @api it works fine up to moment of button click.

Here is my simple model:

from odoo import models, fields, api

class la_shipping(models.Model):
_name = 'tralalal'
_description = 'Tralala'
@api.multi
def button_done(self):
for rec in self:
rec.write({'state', 'done'})
state = fields.Selection([('sent', 'Sent'),('done','Done')],
required =True, default='sent')
<header>
    <button name="button_done" string="Done" states="sent" class="oe_highlight" type="object"></button>
    <button name="button_sent" string="Sent" states="sent,done" class="oe_highlight" type="object"></button>
    <field name="state" widget="statusbar"></field>
</header>
Avatar
Discard

Hi Kirill,

We no need to use any @api decorators for handling multiple records it's by default handling in Odoo 13.

Best Answer

Hi Kirill: 

@api.multi has been deprecated in odoo13. 

Are you facing these issues with any of the other @api values ?

EDIT:

In your case, use ​@api.model  if the action will be performed on a record. If the action is not on a specific record, you don't need a decorator.

If you still encounter issues, another way of doing this would be to configure a Server Action using the UI (​Settings > Technical > Server Actions) and link it to the button using the server action id in the XML.

You may find the following video helpful. Even though it's based on v12, the concepts are applicable to v13.

Odoo V12 - Creating Buttons & Server Actions

Avatar
Discard
Author Best Answer

Hi Paresh:

Yes, doesn't matter which @api I use as far as " @api " written in model odoo stop working. By the way is it any other ways to assign function to button?

Avatar
Discard

You face issues in handling onchange @api?

Hi Kirill: I've edited my original response based on your clarification.

Best Answer

Hello!!!

From 0doo-13 @api.multi is deprecated. For making any function to button you don't need to use any @api, but if you want to pass any args or values in that funtion than you have to use @api.model for that..


Avatar
Discard
Related Posts Replies Views Activity
4
Mar 21
3422
1
Nov 24
150
1
Apr 23
1469
2
Mar 23
7961
2
Mar 23
917