Akhil Mathew
Akhil Mathew

Reputation: 1659

Giving attribute error when i override create function in odoo

In my module i have overridden the create method as follows,

def create(self,vals):
    self.setState()
    return super(class_name,self).create(vals)

def setState(self):
    self.temp = False

It is giving attribute error as env not found in the model. How to rectify it

Upvotes: 0

Views: 265

Answers (2)

Akhil Mathew
Akhil Mathew

Reputation: 1659

In this way we can override create and write method in new API

@api.model
def create(self,vals):
    //Your code goes here//
    return super(class_name, self).create(vals)

@api.multi
def write(self,vals,context=None):
    //Your code goes here//
    return super(class_name,self).write(vals)

Upvotes: 1

cgs
cgs

Reputation: 342

Is temp a regular boolean field on the model? - Then you could just do this:

@api.model
def create(self,vals):
    vals['temp'] = False
    return super(class_name,self).create(vals)

Upvotes: 2

Related Questions