简体   繁体   English

如何在 Odoo 10 的看板视图中显示选择字段的所有阶段(甚至是空的阶段)?

[英]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 .我正在尝试在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.我有一个包含 3 个阶段和看板视图的选择字段。 I used bellow code in my xml to display them the stages in Kanban view.我在我的 xml 中使用了波纹管代码来在看板视图中显示他们的阶段。

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:有xml部分,我使用看板视图中的选择字段在视图中显示:

<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.我搜索了很多,找到了与此问题相关的https://stackoverflow.com/a/40761734/2498426解决方案。 but it was not clear for my case (Selection field).但我的情况不清楚(选择字段)。

it's working for me in Python File:它在 Python 文件中对我有用:

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:在 XML 文件中:

...<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使用 group expand 参数在 hr_contract 模块中找到了一个很好的例子

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.我尝试通过在 Odoo10 中应用Explorer解决方案来实现静态阶段,并且也在 Odoo12 中发现了此功能,但它在 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:然后我在这个模型中添加了 3 条记录作为 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:为了将checklist.stage模型的记录作为模型的看板视图中的阶段,我使用了一个 Many2one 字段,如下所示,带有group_expand以在看板视图中包含所有阶段:

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:对于 group_expand 我使用以下代码作为 _expand_satages 方法:

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.最后在看板视图中,我刚刚向看板元素添加了default_group_by="stage"group_create="false" Although, it's a little long but it worked in my case.虽然,它有点长,但它在我的情况下工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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