Created
June 23, 2022 07:58
-
-
Save sehrishnaz/142d8ed964fad7c01718e8936513252e to your computer and use it in GitHub Desktop.
Dynamically Fold Kanban States (Selection Field) in Odoo8
This file contains hidden or 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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is there a way to do this for odoo 15? ive been looking for one, even trying to do one but i cant