-
How to override create method
over 8 years ago
-
over 7 years ago
Hi all,
In overriding create/write method you should be carefull !!
lets take an example,
def create(self,cr,uid,vals,context):
res=super(class_name,self).create(cr,uid,vals)
# do anything with your logic #
return res
So, While overriding the orm method you should first call the super class create method and and apply your logic and after that just return that res variable
-
-
over 8 years ago
syntex:
@api.model
def create(self, vals):
# do something here return super(class_name, self).create(vals)
example: if you want to override the sale object create method, do something like code into the file
@api.model
def create(self, vals):
# do something record = super(SaleOrder, self).create(vals) # do something, if you want to do otherwise return return record
check here more about override the method live example:
https://github.com/odoo/odoo/blob/master/addons/account/models/account.py#L404
-
-
over 8 years ago
def create(self, cr, uid, vals, context=None): -->Method Returns to Super Method
vals['allday']=False eventid=super(modelname, self).create(cr, uid, vals, context=context) meetingobj=self.browse(cr,uid,eventid,context=context) Your code Here.................. return eventid
def create(self, cr, uid, vals, context=None): -->Method Returns to Super Method vals['all_day'] = False Your code Here.................... return super(modelname, self).create(cr, uid, vals, context=context)
If you want to Omit your base create method and need to create your own method means , Use following code.This method is not return to Super create method.
def create(self, cr, uid, vals, context=None): vals['all_day'] = False Your code Here.................... res = osv.osv.write(self, cr, uid, ids, values, context=context) return res
-
-
over 8 years ago
class res_users(models.Model): _inherit ='res.users'
@api.model def create(self, vals): #Write your logic here print 'Fields and their values to be created in a dictionary',vals res = super(res_users, self).create(vals) #Write your logic here return res
full details here: http://odootechnical.com/learn-overriding-create-method-in-odoo-8/
-
4 Answer(s)