Odoo Help


How to add data in a model using .create?

on 9/11/14, 11:50 PM 947 views
  1. class awb_sss_table(osv.osv):
  2.     _name = 'awb.sss.table'
  3.     _description = 'SSS Contribution Table'
  4.     _columns = {
  5.                 'min_range': fields.float('Minimum Range', help = "minimum range of salary", readonly=True),
  6.                 'max_range': fields.float('Maximum Range', help = "maximum range of salary", readonly=True),
  7.                 'total_contribution': fields.float('Total Contribution', help = "total contribution of employee depending on salary", readonly=True)
  8.                }
  9.     def create_sss(self, cr, uid, vals, context=None):
  10.         vals = []
  11.         sss_model = self.pool.get('awb.sss.table')
  13.         sss_model.create(cr, uid, {'min_range': 1000.0, 'max_range': 1249.99, 'total_contribution': 120.0}, context=context)
  14. awb_sss_table()


there's no error but the data is not saved in my custom model. please help thanks

"sss_model = self.pool.get('awb.sss.table')" is also unnecessary, since you're already in the awb.sss.table object. Rather than doing sss_model.create(), you can just do self.create(). Why are you adding a static set of defaults? You might as well just set _defaults={'min_range':1000,'max_range':1249.99,'total_contribution':120} and ignore the create_sss() function entirely.

Brett Lehrer
on 9/13/14, 2:28 PM
On 9/12/14, 8:46 AM

Hi Paolo, the problem is you need to return the control to standard create method of your object.

def create_sss(self, cr, uid, vals, context=None):
       vals = []
       sss_model = self.pool.get('awb.sss.table')
       return super(awb_sss_table,self).create(cr, uid, {'min_range': 1000.0, 'max_range': 1249.99, 'total_contribution': 120.0}, context=context)


super() is not necessary because the function is named create_sss(). If the function was named create() because you wanted to add some additional processing before or after the actual record creation.

Brett Lehrer
on 9/13/14, 2:25 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/11/14, 11:50 PM
Seen: 947 times
Last updated: 3/16/15, 8:10 AM