Kanban view is probably the most flexible view in Odoo. It can be used for many different purposes. One of the most common ones is splitting items into distinct groups (represented by a row of columns) and allowing users to drag items between those groups. For example the hr_reqruitment
module lets users to manage applications this way.
It’s trivial and well documented how to group objects in Kanban. Just add default_group_by
attribute to the <kanban>
element:
There is however a potential problem. Columns representing groups without any items will not be included. This means users won’t be able to move items to those absent groups, which is probably not what we intended.
Oddo has an answer for this ready - an optional model attribute called _group_by_full
. It should be a dictionary, mapping field names (of the fields you use for grouping) to methods returning information about all available groups for those fields.
The code above ensures that when displaying store
objects grouped by company_id
, all available companies will be represented (and not only those already having stores).
Methods listed in _group_by_full
need to return a two element tuple:
First element: a list of two element tuples, representing individual groups. Every tuple in the list need to include the particular group’s value (in our example: id of a particular company) and a user friendly name for the group (in our example: company’s name). That’s why we can use the name_get
method, since it returns a list of (object id, object name)
tuples.
Second element: a dictionary mapping groups’ values to a boolean value, indicating whether the group should be folded in Kanban view. Not including a group in this dictionary has the same meaning as mapping it to False
.
For example this version of company_groups
method would make group representing a company with id 1
folded in Kanban view:
many2one
There seem to be problem in Odoo 8.0 preventing use of _group_by_full
with fields other than many2one
. I got around the issue extending the _read_group_fill_results
method. Here is an example of grouping by the state
field:
Comments
© Ludwik Trammer, 2014 — built with Jekyll using Lagom theme