Odoo Help


This community 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.


How insert with requete Insert Into in database ?

on 2/12/14, 7:22 AM 1,331 views

I try insert in database new entry in sale order :

    def test_mdel(self, cr, uid, id, vals, default=None, context=None):
    #val['name'] =self.pool.get('ir.sequence').get(cr, uid, 'sale.order') 
    #return super(sale_order, self).create(cr, uid, val, context=context)
    #self.write(cr, uid, ids, {'name': 'ffdfdd'})
    #val2 = vals.get('x_num_devis')

    cr.execute("SELECT nextval('sale_order_id_seq') FROM sale_order")
    next_id = cr.fetchone()[0]

    cr.execute("INSERT INTO sale_order (id,name,shop_id,date_order,partner_id,partner_invoice_id,partner_shipping_id,pricelist_id,currency_id,invoice_quantity) VALUES (%s,%s,%s,(now() at time zone 'UTC'),%s,%s,%s,%s,%s,%s)",(next_id,'test',1,6,6,6,1,'order'))
    msg = "Test " +str(next_id) 
    #new_id = self.pool.get('sale.order').create(cr, uid, {'name': 'New Name'})
    #cr.execute("Insert into sale_order (id) values (%s) where id=%d",(id))
    #INSERT INTO sale_order (write_date) VALUES ( (now() at time zone 'UTC'))
    return True

But when i try this, i have a error :

Server Traceback (most recent call last):

File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, args, *kwargs) File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/usr/lib/pymodules/python2.7/openerp/addons/Complement/complement.py", line 72, in test_mdel cr.execute("INSERT INTO sale_order (id,name,shop_id,date_order,partner_id,partner_invoice_id,partner_shipping_id,pricelist_id,currency_id,invoice_quantity) VALUES (%s,%s,%s,(now() at time zone 'UTC'),%s,%s,%s,%s,%s,%s)",(next_id,'test',1,6,6,6,1,'order')) File "/usr/lib/pymodules/python2.7/openerp/sql_db.py", line 161, in wrapper return f(self, args, *kwargs) File "/usr/lib/pymodules/python2.7/openerp/sql_db.py", line 226, in execute res = self._obj.execute(query, params) IndexError: tuple index out of range

help me please

On 7/1/14, 7:22 PM


I do not apply this way to insert records, but I'd say you have 9 parameters% s and 8 values

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 2/12/14, 7:22 AM
Seen: 1331 times
Last updated: 3/16/15, 8:10 AM