Odoo Help

Welcome!

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.

0

TypeError: cannot convert dictionary update sequence element #0 to a sequence

By
Dr Obx
on 1/5/16, 5:55 AM 3,123 views

[code]

....

   'current_stock': fields.function(_get_current_stock, type='char', string='Currently in stock'),
....


 #getting quants from stock.quant to put into field 'current_stock'

def _get_current_stock(self, cr, uid, ids, field_name, arg, context=None):

res = []

in_stock = 0

tot_sold = 0

product_id = 0

for obj in self.browse(cr, uid, ids, context=context):

#first query read data about product sold
cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id = 7;""" %(obj.product_id.id))
tot_sold = cr.fetchall()

#second query read data adout products left in stock
cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(obj.product_id.id))
in_stock = cr.fetchall()

res = in_stock[0]    <= once i add this, everything stops and getting error, of course if I remove it got no error but also current_stock stays empty because res = ''

# I can print value of tot_sold and in_stock
print '|| Total sell: ', tot_sold[0], ' Left in stock: ',in_stock[0]

return res

 Getting this error and don't know how to extract data from res and populate with related field 'current_stock'

new_values = dict(values)

TypeError: cannot convert dictionary update sequence element #0 to a sequence

Please use significant titles, this forum rule is also valid for newbies :-)

Ermin Trevisan
on 1/6/16, 3:32 AM
1

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 1/5/16, 6:09 AM

Hello Dr Obx,

I guess the problem is that you are not passing the value to associated record.

Try following code:

res[obj.id] = in_stock[0]

Reference: Function Field.

Hope this will help you.

Thank you Serpent :) Unfortunately still getting error, but this time: File "/usr/lib/python2.7/dist-packages/openerp/addons/iProdLoc/iprodloc.py", line 229, in _get_current_stock res[obj.id] = in_stock[0] IndexError: list assignment index out of range

Dr Obx
on 1/5/16, 6:27 AM

You must check whether there are any records and then set in_stock[0]! Set like res[obj.id] = len(in_stock) !=0 and in_stock[0] or False.

Serpent Consulting Services Pvt. Ltd.
on 1/5/16, 6:54 AM

So far I managed to partially solve the problem, now I don't get those errors anymore but still cant put value into my field ;)

Dr Obx
on 1/6/16, 7:15 AM

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)

Stats

Asked: 1/5/16, 5:55 AM
Seen: 3123 times
Last updated: 1/6/16, 3:31 AM