I have a little piece of one of my scripts that works perfectly fine on Python but always raise an IndexError under Odoo:
for nt in newTable:
(the next line is obviously an extract of the newTable list)
nt = [21562, 7161, 'Cotto GR', '+ Muss. Vegetal', Decimal('1.0'), 'Mesa 05', 'A fazer', 'N', '0', datetime.datetime(2017, 2, 9, 10, 57, 27)]
items in list = 10
self.env.cr.execute(sql_write_ord, (nt))
self.env.cr.commit()
In python the syntax works fine, the nt list contains 10 items, as asked by the INSERT INTO sql call, but in odoo I get:
File "/odoo_test2/odoo_test2-server/addons/divina_v10/models/divina_pos_V10.py", line 111, in _compute_kot_lines self.env.cr.execute(sql_write_ord, (nt)) File "/odoo_test2/odoo_test2-server/odoo/sql_db.py", line 141, in wrapper return f(self, *args, **kwargs) File "/odoo_test2/odoo_test2-server/odoo/sql_db.py", line 218, in execute res = self._obj.execute(query, params)IndexError: tuple index out of range
For now I've tested with:
self.env.cr.execute(sql_write_ord, [nt[0], nt[1], nt[2], nt[3], nt[4], nt[5], nt[6], nt[7], nt[8], nt[9]])
and
self.env.cr.execute(sql_write_ord, ([tuple(nt)]))
but raise the same error.
Solved:
There are many logs on my code and I found the error of tuple index out of range is generated by the first tuple in newTable, This issue is not present under Python. To solve the problem I was obliged to flush newTable before starting to populate it, because the first list is created (and I still don't know why since in Python is fine) with just 7 items out of 10, then generate the error.