İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
10791 Görünümler

I've found many sources without any successful result.


I need to show all kanban's stages even if there aren't objects in the stage, as the title says, I'm using a selection field as steps list, this selection field is the state special field.


I know how to show all stages using a Many2one field, but not using Selection field, also I've found nothing on the internet.


Is not necessary put code here in this question though.

Avatar
Vazgeç
Üretici En İyi Yanıt

After a lot of searching stuff, I found a solution I did override the read_group method:


@api.model
    def read_group(self,
                   domain,
                   fields,
                   groupby,
                   offset=0,
                   limit=None,
                   orderby=False,
                   lazy=True):
        """ Override read_group to always display all states. """
        if groupby and groupby[0] == "state":
            # Default result structure
            states = [('new', _('New')), ('assign', _('Assigned')),
                      ('evaluate', _('Evaluating')), ('done', _('Done')),
                      ('cancel', _('Cancel'))]
            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]
            # Get standard results
            read_group_res = super(Maintenance, self).read_group(
                domain,
                fields,
                groupby,
                offset=offset,
                limit=limit,
                orderby=orderby)
            # Update standard results with default results
            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(Maintenance, self).read_group(
                domain,
                fields,
                groupby,
                offset=offset,
                limit=limit,
                orderby=orderby)
Avatar
Vazgeç

I used your code, it's working on v13 with following modifications:

1- the line filter(lambda x: x['state'] == state_value, read_group_res) will return a filter object, so it should be wrapped with list().

same for filter(lambda x: x['state'] == state_value, read_group_all_states).

2- the line res[0]['state'] = [state_value, state_name] will result in state names be false in the front end, because the default structure now uses only 'state_value' not a list of [state_value, state_name]

3- you ignored the parameter 'lazy' when calling the super function it should be there to properly execute the function.

En İyi Yanıt

I think there is no need to override read_group.
Define group_expand attribute on the field and kanban view display all the stages even if there is no record in this stage

ref: https://github.com/odoo/odoo/blob/13.0/addons/mass_mailing/models/mailing.py#L86-L87
https://github.com/odoo/odoo/blob/13.0/addons/mass_mailing/models/mailing.py#L256

Avatar
Vazgeç

This is the correct answer.
Here's an example on how to achieve it.

state = fields.Selection(SELECTION_OPTIONS, .........., group_expand="_group_expand_states")
def _group_expand_states(self, states, domain, order):
return [state[0] for state in SELECTION_OPTIONS]

En İyi Yanıt

Just in case someone would come by here and want to know:


If you go in the Debug -> Modify Action, and add in the context {'default_project_id': x} (x being the actual project ID), it will do the trick.


At least from 15>, didn't try on


Coming from standard:




    @api.model


    def _read_group_stage_ids(self, stages, domain, order):


        search_domain = [('id', 'in', stages.ids)]


        if 'default_project_id' in self.env.context:


            search_domain = ['|', ('project_ids', '=', self.env.context['default_project_id'])] + search_domain


        stage_ids = stages._search(search_domain, order=order, access_rights_uid=SUPERUSER_ID)


        return stages.browse(stage_ids)

Avatar
Vazgeç
En İyi Yanıt

a cleaner version of the solution, also adapted to be able to work with v13:

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
""" Override read_group to always display all states. """
group_by_field = 'stage'
group_by_selection = self._fields[group_by_field].selection
if groupby and groupby[0] == group_by_field:
# Default result structure
read_group_all_states = [{
'__context': {'group_by': groupby[1:]},
group_by_field + '_count': 0,
'__domain': domain + [(group_by_field, '=', selection_key)],
group_by_field: selection_key, }
for selection_key, selection_value in group_by_selection]
# Get standard results
read_group_res = super(Repairs, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
# Update standard results with default results
result = []
for selection_key, selection_value in group_by_selection:
res = list(filter(lambda x: x[group_by_field] == selection_key, read_group_res))
if not res:
res = list(filter(lambda x: x[group_by_field] == selection_key, read_group_all_states))
result.append(res[0])
return result
else:
return super(Repairs, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
Avatar
Vazgeç