Odoo Help

0

Is it necessary to use @api.one or @api.multi in all methods of a model?

By
Eduardo BP
on 6/19/15, 4:26 PM 1,311 views

Hi,

I'm wondering whether it is necessary to use @api.one or @api.multi in all methods of a model?.

In my case, I have implemented a workflow. In this one, I have built a transition that only triggers if a condition is evaluated to True.

<record id="coming_soon_to_discontinued_end_date" model="workflow.transition">
<field name="act_from" ref="state_coming_soon"/>
<field name="act_to" ref="state_discontinued"/>
<field name="condition">end_date_reached()</field>
</record>

The condition is evaluated through a method in my model:

class Product(models.AbstractModel):
_name = 'sdicrm.product'
...
def end_date_reached(self):
end_date = fields.Date.from_string(self.end_date_sale)
return end_date < date.today()

What I don't know is whether I have to use @api.one decorator in the 'end_date_reached' method:

@api.one
def end_date_reached(self):
end_date = fields.Date.from_string(self.end_date_sale)
return end_date < date.today()

Thank you.

0

Hi,

It is not mandatory. If you want to use Odoo V8 API then you need to use @api.one or @api.multi. Otherwise no need to use it.

Just make code as like OpenERP V7 without any decorator. thats it.

 

Hi, but I don't want to use the old API but the new one. What I don't know is whether I have to use @api.one or @api.multi in all of my methods of my module using the new API.

Eduardo BP
on 6/20/15, 10:44 AM

You need to use @api.one and @api.multi in appropriate case. Please have a look on the doc. http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html#api-one

Emipro Technologies Pvt. Ltd.
on 6/22/15, 12:58 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/19/15, 4:26 PM
Seen: 1311 times
Last updated: 6/20/15, 2:55 AM