Create Write Unlink

Create Method





class Campus(models.Model): _name='campus' @api.model def create(self,values): campus_create = super(Campus,self).create(values) return campus_create

class Campus(models.Model): _name='campus' @api.multi def write(self,values): campus_write = super(Campus,self).write(values) return campus_write

class Campus(models.Model): _name='campus' @api.multi def unlink(self,values): campus_unlink = super(Campus,self).unlink() return campus_unlink

Code Description:

In this article you will learn how to override Odoo methods. I will show you how to override Odoo Create, Write and Unlink method. Here the question is why we need to override these () methods.The answer is to add or remove additional functionality we use overriding. For example if I want to check some constraints before creating, editing or deleting our record than we may use Odoo override methods.There are basically three methods which we can override.The create method invoke every time when we click on "Create" or "New" button on Odoo form view and when we save the from using Save button.Below is the code snippet to override create method.Below is the code snippet to override write method.Below is the code snippet to override unlink method.In above code we have a "Campus" class and we override campus class create, write or unlink method. @api.model is a decorator that decorate a record style method. Notice here to override you should call super() method. Super method takes two parameter the first one is the name of class which is "Campus" and the second one is "self". Where self is a record set in which model the record is created. Values are dictionary that contains data which we are going to create, write or unlink.