Show all states in Kanban View

The kanban view in Odoo is a kanban board type visualization.it displays records as “cards”, as a mixture of a list view and a non-editable form view. Records can be merged/grouped in columns for use in workflow display or manipulation (e.g. Customers or Lead-Opportunity management), or ungrouped (used basically to display records).


We were working on one of the projects where we had a requirement related to kanban View. There were few states in form view which were clickable in form view.The problem which we came across was it used to show only those states which were having records.For Ex: If I have one record in Draft state and one record in In Progress state, so in Kanban View, we  were able to see those two states only and not other states like Done and Cancelled etc. It was important for us to display all states in kanban view as we wanted to make good use of Drag & Drop feature of kanban view.

Then we implemented this requirement by overriding the read_group to always display all states. You can have look at following code snippet for the logic to override the read_group function.By this logic,we were able to show all states in kanban view irrespective of records present in it or not.And now we can make full use of Drag & Drop feature of kanban view.

def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):

if groupby and groupby[0] == “state”:

states = [(‘draft’, ‘Draft’), (‘in_progress’, ‘In Progress’), (‘done’, ‘Done’)]

read_group_all_states = [{
‘__context’: {‘group_by’: groupby[1:]},
‘__domain’: domain + [(‘state’, ‘=’, state_value)],
‘state’: state_value,
‘state_count’: 0,
} for state_value, state_name in states]

read_group_res = super(your_class_name, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)

result = []

for state_value, state_name in states:

res = filter(lambda x: x[‘state’] == state_value, read_group_res)

if not res:

res = filter(lambda x: x[‘state’] == state_value, read_group_all_states)

res[0][‘state’] = [state_value, state_name]
result.append(res[0])

return result

else:

return super(your_class_name, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)

and that’s how we implemented above requirement to display all states in Kanban View.

You must be logged in to post a comment.