Odoo / Model / Override Create, Write and Unlink function
Override Functions
-
Step 1:
1. override_create_function
class your_model(models.Model): _name='your.model' # Override Create Function @api.model def create(self,values): # your logic goes here override_create = super(your_model,self).create(values) return override_create eg:
record = self.env['your.model'].create({ 'name': 'Example' }) 2. override_write_function
class your_model(models.Model): _name='your.model' # Override Write Function @api.multi def write(self,values): # your logic goes here override_write = super(your_model,self).write(values) return override_write eg:
record_ids = self.env['your.model'].search([('name', '=', 'Example')]) for record in record_ids: record.write({ 'some_field': 'some_description' }) 3. override_unlink_function
class your_model(models.Model): _name='your.model' #Override Unlink Function @api.multi def unlink(self,values): #your logic goes here override_unlink = super(your_model,self).unlink() return override_unlink