1
votes

"Error" File "/home/tushar/odoo1/openerp/fields.py", line 1528, in get_values return [value for value, _ in selection]

TypeError: 'NoneType' object is not iterable

Stachtrace: Odoo Server Error

Traceback (most recent call last):
  File "/home/tushar/odoo1/openerp/http.py", line 648, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/tushar/odoo1/openerp/http.py", line 685, in dispatch
    result = self._call_function(**self.params)
  File "/home/tushar/odoo1/openerp/http.py", line 321, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/http.py", line 314, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/tushar/odoo1/openerp/http.py", line 964, in __call__
    return self.method(*args, **kw)
  File "/home/tushar/odoo1/openerp/http.py", line 514, in response_wrap
    response = f(*args, **kw)
  File "/home/tushar/odoo1/addons/web/controllers/main.py", line 888, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/tushar/odoo1/addons/web/controllers/main.py", line 880, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/api.py", line 381, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/models.py", line 6028, in onchange
    record = self.new(values)
  File "/home/tushar/odoo1/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/tushar/odoo1/openerp/models.py", line 5595, in new
    record._cache.update(record._convert_to_cache(values, update=True))
  File "/home/tushar/odoo1/openerp/models.py", line 5490, in _convert_to_cache
    for name, value in values.iteritems()
  File "/home/tushar/odoo1/openerp/models.py", line 5491, in <dictcomp>
    if name in fields
  File "/home/tushar/odoo1/openerp/fields.py", line 1533, in convert_to_cache
    if value in self.get_values(record.env):
  File "/home/tushar/odoo1/openerp/fields.py", line 1528, in get_values
    return [value for value, _ in selection]
TypeError: 'NoneType' object is not iterable

I got This Error for dynamic selection for selection field in odoo. I provide the code I have done. Please help me out of this

from  openerp import models, fields, api
from test.test_support import temp_cwd

class scantech_laser_product_template(models.Model):
    _name='product.template' 
    _inherit='product.template'

    values2=[('ECDS0','ECDS0'),('ECDS1','ECDS1'),('ECDS2','ECDS2')]    
    main_category = fields.Selection([('SL0','SL0'),('SL1','SL1'),('SL2','SL2')],string="Main Category")

    @api.multi 
    @api.depends("main_category")
    def _get_selection_name(self):
        if self.main_category == "SL0":
            return [("ESDS1","ESDS1")]  

    sub_category = fields.Selection(selection=_get_selection_name,string="Sub Category")

When I am selecting the main category field it showing above error

1
Please provide the complete stacktraceAnonymous
I provided stacktrace as u saidTushar Rmesh Saindane

1 Answers

0
votes

The problem is that you're not returning a default value when your condition evaluates to false (and functions/methods in python that return nothing return None) so a workaround would be to do something like this

@api.multi 
@api.depends("main_category")
def _get_selection_name(self):
    if self.main_category == "SL0":
        return [("ESDS1","ESDS1")]

    return [("default", "Default")] # can be anything you want as the default value

or you can make your selection field have a default value, which makes the condition to always evaluate to true and eliminates the need for a default return value in _get_selection_name

main_category = fields.Selection([('SL0','SL0'),('SL1','SL1'),('SL2','SL2')],string="Main Category", default="SLO")