Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'api' is not defined

Im trying to develop my first module on odoo 9.0 following the documentation and a developer manual for odoo, using the "TO-DO Tasks" example, but im having problems when I try to add a functionality to one of my buttons, in the manual says I have to add this code to my class file (todo_model.py).

@api.one
def do_toggle_done(self):
    self.is_done = not self.is_done
    return True

But when I update the module on Odoo I got this message:

NameError: name 'api' is not defined

This is my todo_model.py

# -*- encoding utf-8 -*-
from openerp import models,fields

class TodoTask(models.Model):
    _name   =   "todo.task"
    name    =   fields.Char('Description', required=True)
    is_done =   fields.Boolean('Done?')
    active  =   fields.Boolean('Active?', default=True)

    @api.one
    def do_toggle_done(self):
         self.is_done = not self.is_done
         return True

Best regards.

like image 647
NMenam Avatar asked Oct 14 '25 13:10

NMenam


1 Answers

You forgot to import api

Try with following:

from openerp import api,models,fields
like image 110
Bhavesh Odedra Avatar answered Oct 17 '25 11:10

Bhavesh Odedra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!