In this article, you will learn how to fold/unfold (selection field) states (not many2one field), in kanban view in Odoo8. The Kanban view is the most attractive and flexible in Odoo. By using this view we can split items into distinct groups (in the form of a row of columns).
Fold/Unfold fields in Kanban View other than many2one
Read More: Remove Fold,Edit Stage,Delete and Archive All From Task Kanban View
Other than many2one fields mean than in this article we are going to fold and unfold states (Selection field, not many2one) based on states.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class some_model(models.Model): | |
_name = "some.model" | |
STATES = [('Draft','Draft'),('Submit','Submit'),('Closed','Closed')] | |
# States that should be folded in Kanban view | |
# used by the `state_groups` method | |
FOLDED_STATES = [ | |
'Closed', | |
] | |
@api.model | |
def state_groups(self, present_ids, domain, **kwargs): | |
folded = {key: (key in self.FOLDED_STATES) for key, _ in self.STATES} | |
# Need to copy self.STATES list before returning it, | |
# because odoo modifies the list it gets, | |
# emptying it in the process. Bad odoo! | |
return self.STATES[:], folded | |
_group_by_full = { | |
'state': state_groups | |
} | |
state = fields.Selection(STATES, string="Status", default="Draft") | |
def _read_group_fill_results(self, cr, uid, domain, groupby, | |
remaining_groupbys, aggregated_fields, | |
count_field, read_group_result, | |
read_group_order=None, context=None): | |
""" | |
The method seems to support grouping using m2o fields only, | |
while we want to group by a simple status field. | |
Hence the code below - it replaces simple status values | |
with (value, name) tuples. | |
""" | |
if groupby == 'state': | |
STATES_DICT = dict(self.STATES) | |
for result in read_group_result: | |
state = result['state'] | |
result['state'] = (state, STATES_DICT.get(state)) | |
return super(some_model, self)._read_group_fill_results( | |
cr, uid, domain, groupby, remaining_groupbys, aggregated_fields, | |
count_field, read_group_result, read_group_order, context | |
) |
0 Comments