简体   繁体   中英

How to display all stages (even empty ones) of a selection field in Kanban view in Odoo 10?

I am trying to display stages for a model defined as a Selection field in Kanban view in Odoo 10 . But when I add the stage field in Kanban view, stages with records in it are displayed in kanban view but not all stages.

I have a Selection field with 3 stages and a Kanban view. I used bellow code in my xml to display them the stages in Kanban view.

This is my Selection field:

stage = fields.Selection([
        ('not reviewed', 'Not Reviewed'), 
        ('review in progress', 'Review In Progress'), 
        ('review complete', 'Review Complete')
    ], default='not reviewed')

There is the xml part where I use the Selection field in the kanban view to be displayed in view:

<record id="sources_daily_review_kanban_view" model="ir.ui.view">
        <field name="name">Daily Sources Review Kanban</field>
        <field name="model">daily.source.review</field>
        <field name="arch" type="xml">
            <kanban default_group_by="stage" class="o_kanban_small_column o_opportunity_kanban">
                <field name="stage" options='{"group_by_tooltip": {"requirments": "Description", "legend_priority": "Use of stars"}}'/>
                <field name="color"/>
                <field name="name"/>
                <field name="description"/>
                <field name="responsible"/>
                <field name="active"/>
                <field name="source_date"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click">
                           <div class="o_dropdown_kanban dropdown">
                                <a class="dropdown-toggle btn" data-toggle="dropdown" href="#">
                                    <span class="fa fa-bars fa-log"/>
                                </a>
                                <ul class="dropdown-menu" role="menu" area-labelledby="dLabel">
                                    <t t-if="widget.editable"><li><a type="edit">Edit</a></li></t> 
                                    <t t-if="widget.deletable"><li><a type="delete">Delete</a></li></t>
                                    <li t-if="! record.active.value"><a name="action_set_active" type="object">Unarchive</a></li>
                                    <li t-if="record.active.value"><a name="action_set_unactive"  type="object">Archive</a></li>
                                    <li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                </ul>
                           </div>
                           <div class="oe_kanban_content">
                                <div>
                                    <field name="tag_ids"/>
                                </div>
                                <div>
                                    <strong><field name="name" domain="[('including_in_daily_review', '=', True)]"/></strong>
                                </div>
                                <div>
                                    <field name="description"/>
                                </div>
                                <div>
                                    <field name="responsible"/>
                                </div>
                                <div class="oe_kanban_footer">

                                </div>
                           </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
</record>

This code displays only those stages which there is a record in that stage while I want all stages to be displayed even the empty ones. I searched a lot and find https://stackoverflow.com/a/40761734/2498426 solution related to this problem. but it was not clear for my case (Selection field).

it's working for me in Python File:

state = fields.Selection([('en_cours_confirmation', 'En Cours de Confirmation'), ('confirmer', 'Confirmé'), ('annuler', 'Annulé')]
                         , default='en_cours_confirmation', string="Status",  group_expand='_expand_states', index=True)

def _expand_states(self, states, domain, order):
    return [key for key, val in type(self).state.selection]

in XML File:

...<kanban colors="blue:state=='en_cours_confirmation';red:state=='annuler';grey:state=='confirmer'" default_group_by="state">...

Use the group expand parameter a good example is found in hr_contract module

stage = fields.Selection([
    ('not reviewed', 'Not Reviewed'), 
    ('review in progress', 'Review In Progress'), 
    ('review complete', 'Review Complete')
], default='not reviewed',group_expand='_expand_states')


def _expand_states(self, states, domain, order):
    return [key for key, val in type(self).state.selection]

I tried to have static stages by applying Explorer solution in Odoo10 and also found this feature in Odoo12, but it is not working in Odoo10. So, I used bellow technique to have static and fixed stages even with empty columns in Kanban view:

First I defined a new Model as bellow:

class CheckListStage(models.Model):

    _name = "checklist.stage"
    _rec_name = "name"
    _sequence = "sequence, name, id"

    name = fields.Text(string='Name', required=True, translate=True)
    sequence = fields.Integer('Sequence', default=1, help='Used to order stages. Lower is better.')

Then I added 3 records to this model as a data file in xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="stage_not_reviewed" model="checklist.stage">
            <field name="name">Not Review</field>
            <field name="sequence">1</field>
        </record>

        <record id="stage_review_in_progress" model="checklist.stage">
            <field name="name">Review In Progress</field>
            <field name="sequence">2</field>
        </record>
        
        <record id="stage_review_complete" model="checklist.stage">
            <field name="name">Review Complete</field>
            <field name="sequence">3</field>
        </record>
    </data>
</odoo>

For having records of checklist.stage model as stages in my Kanban view of the model, I used a Many2one field as bellow with group_expand to have all the stages in the Kanban view:

stage = fields.Many2one('checklist.stage', group_expand='_expand_stages', default=lambda self: self._default_stage())

For group_expand I used following code as _expand_satages method:

def _expand_stages(self, states, domain, order):
        stage_ids = self.env['checklist.stage'].search([])
        return stage_ids

Finally in the Kanban view I just added default_group_by="stage" and group_create="false" to the Kanban element. Although, it's a little long but it worked in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM