简体   繁体   中英

How to show static state values in kanban view Odoo10?

I have state filed which is a Selection field. I want to group the records based on this state field in kanban view.

here is my code:

* .py

  state = fields.Selection([('draft','Draft'),('process','Processing')
        ,('intransit','In-transit'),('done','Delivered'),('cancel','Canceled')],
        default="draft",string="Status", track_visibility="onchange",
        group_expand='_expand_states',index=True)

  @api.model
  def _expand_states(self, states, domain, order):
      return [key for key, val in type(self).state.selection]

But i am getting this error:

> Traceback (most recent call last):
  File "/home/user/Projects/odoo-10/odoo/http.py", line 642, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/user/Projects/odoo-10/odoo/http.py", line 684, in dispatch
    result = self._call_function(**self.params)
  File "/home/user/Projects/odoo-10/odoo/http.py", line 334, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/user/Projects/odoo-10/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/user/Projects/odoo-10/odoo/http.py", line 327, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/user/Projects/odoo-10/odoo/http.py", line 942, in __call__
    return self.method(*args, **kw)
  File "/home/user/Projects/odoo-10/odoo/http.py", line 507, in response_wrap
    response = f(*args, **kw)
  File "/home/user/Projects/odoo-10/odoo/addons/web/controllers/main.py", line 895, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/user/Projects/odoo-10/odoo/addons/web/controllers/main.py", line 887, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/user/Projects/odoo-10/odoo/api.py", line 687, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/home/user/Projects/odoo-10/odoo/api.py", line 672, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/home/user/Projects/odoo-10/odoo/models.py", line 1939, in read_group
    result = self._read_group_raw(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
  File "/home/user/Projects/odoo-10/odoo/models.py", line 2052, in _read_group_raw
    aggregated_fields, count_field, result, read_group_order=order,
  File "/home/user/Projects/odoo-10/odoo/models.py", line 1680, in _read_group_fill_results
    groups = self.env[field.comodel_name].browse(group_ids)
  File "/home/user/Projects/odoo-10/odoo/api.py", line 760, in __getitem__
    return self.registry[model_name]._browse((), self)
  File "/home/user/Projects/odoo-10/odoo/modules/registry.py", line 177, in __getitem__
    return self.models[model_name]
KeyError: None

How can i solve this?

Have you put default_group_by="state" in xml file where kanban tag is placed as an attribute. Remove the group_expand method and remove attribute from field, because it's a selection field so you don't need to return ids, just place the attribute default_group_by="state" in xml file and you'll see the result.

According to source code documentation , the method defined in group_expand should return a list of all aggregated values that we want to display for this field, in the form of a m2o-like pair (key,label).

The _read_group_fill_results method will always try to get the comodel_name of the field to build groups and because the comodel_name is not defined for selection fields, Odoo will raise a KeyError: None .

Unfortunately, returning a list of values that will be used as groups is available since Odoo-11 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM