NMenam
NMenam

Reputation: 134

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.

Upvotes: 4

Views: 7612

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

You forgot to import api

Try with following:

from openerp import api,models,fields

Upvotes: 6

Related Questions