Displaying a full list of groups in Odoo's Kanban view

Kanban view is probably the most flexible view in Odoo. It can be used for many different purposes. One of the most common ones is splitting items into distinct groups (represented by a row of columns) and allowing users to drag items between those groups. For example the hr_reqruitment module lets users to manage applications this way.

It’s trivial and well documented how to group objects in Kanban. Just adddefault_group_by attribute to the <kanban> element:

<kanban default_group_by="company_id">

Including empty groups

There is however a potential problem.Columns representing groups without any items will not be included. This means users won’t be able to move items to those absent groups, which is probably not what we intended.

Oddo has an answer for this ready - an optional model attribute called _group_by_full. It should be a dictionary, mapping field names (of the fields you use for grouping) to methods returning information about all available groups for those fields.

class Store(models.Model):
    @api.model
    def company_groups(self, present_ids, domain, **kwargs):
        companies = self.env[‘res.company‘].search([]).name_get()
        return companies, None

    _name = ‘store‘
    _group_by_full = {
        ‘company_id‘: company_groups,
    }

    name = fields.Char()
    company_id = fields.Many2many(‘res.company‘)

The code above ensures that when displaying store objects grouped by company_id, all available companies will be represented (and not only those already having stores).

Methods listed in _group_by_full need to return a two element tuple:

  • First element: a list of two element tuples, representing individual groups. Every tuple in the list need to include the particular group’s value (in our example: id of a particular company) and a user friendly name for the group (in our example: company’s name). That’s why we can use the name_get method, since it returns a list of (object id, object name) tuples.
  • Second element: a dictionary mapping groups’ values to a boolean value, indicating whether the group should be folded in Kanban view. Not including a group in this dictionary has the same meaning as mapping it to False.

    For example this version of company_groups method would make group representing a company with id 1 folded in Kanban view:

@api.model
def company_groups(self, present_ids, domain, **kwargs):
    companies = self.env[‘res.company‘].search([]).name_get()
    folded = {1: True}
    return companies, folded

Grouping by fields other than many2one

There seem to be problem in Odoo 8.0 preventing use of _group_by_full with fields other than many2one. I got around the issue extending the _read_group_fill_results method. Here is an example of grouping by the state field:

class Store(models.Model):
    _name = ‘store‘
    STATES = [
        (‘good‘, ‘Good Store‘),
        (‘bad‘, ‘Bad Store‘),
        (‘ugly‘, ‘Ugly Store‘),
    ]

    # States that should be folded in Kanban view
    # used by the `state_groups` method
    FOLDED_STATES = [
        ‘ugly‘,
    ]

    @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
    }

    name = fields.Char()
    state = fields.Selection(STATES, default=‘good‘)

    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(Store, self)._read_group_fill_results(
            cr, uid, domain, groupby, remaining_groupbys, aggregated_fields,
            count_field, read_group_result, read_group_order, context
        )

Displaying a full list of groups in Odoo's Kanban view

时间: 2024-12-11 15:27:42

Displaying a full list of groups in Odoo's Kanban view的相关文章

odoo 基于SQL View视图的model类

在做odoo的过程中,会涉及到多表的查询, 尤其是做报表的时候这种情况更甚,这样下来会做很多的关联,不是很方便.odoo提供了一种机制,即基于视图的model类.代码地址在这里. 具体过程如下: 1.建立model类mssql.employee 1 import logging 2 3 from odoo import models, fields, api 4 from odoo import tools 5 6 _logger = logging.getLogger(__name__) 7

Odoo9.0模块开发全流程

构建Odoo模块 模块组成 业务对象 业务对象声明为Python类, 由Odoo自动载入. 数据文件 XML或CSV文件格式, 在其中声明了元数据(视图或工作流).配置数据(模块参数).演示数据等. Web控制器 处理Web浏览器发来的requests. 静态web数据 Web用到的图像, CSS或JavaScript文件. 模块结构 一个Odoo模块也是一个Python模块, 存放在一个目录中, 包含一个__init__.py文件, 用于导入其他Python模块. from . import

odoo12常用的方法

2019-09-13 今天是中秋节,星期五 #自定义显示名称 def name_get(self): result = [] for order in self: rec_name = "%s(%s)"%(record.name,record.date_done) result.append((record.id, rec_name)) return result # 新添加函数name_search @api.model def name_search(self, name='',

何时调用getView?——从源码的角度给出解答

先来看ListView类中的makeAndAddView方法: 1 /** 2 * 获取视图填充到列表的item中去,视图可以是从未使用过的视图转换过来,也可以是从回收站复用的视图. 3 * 在该方法中,先查找是否有可重用视图,如果有,使用可重用视图. 4 * 然后通过obtainView方法获取一个view(有可能是从未使用视图转换过来 5 * (obtainView方法是在AbsListView方法中定义)),再重新测量和定位View. 6 * Obtain the view and add

[Javascript] Get Started with LeafletJS Mapping

Leaflet makes creating maps in the browser dead simple. With some HTML and 3 lines of JavaScript, we can quickly have a map displaying // create a map in the "map" div, set the view to a given place and zoom var map = L.map('map').setView([51.50

屏姨讶们是h25vhc4y6ece5

说到这里,玄老的声音中明显多了几分悲怆的味道"他们都是好孩子,尽管他们未能真正毕业,但在学院的名册上,始终有着他们的名字.他们以学院的理想为理想,他们并不是没有毕业的实力,而是为了学院的理想战死了."-----------------------------------------------------------------------------周漪忍不住道:"有什么是学院不能帮你解决的?非要自己一个人去面对?难道你说出来我们会不帮你么?"可是--,聚能魂导炮

僦檬哨招瓤kdqg84x5hodqk1

台上,天煞斗罗黄津绪并没有催促双方进行下一场比赛,因为比赛台在刚才一战中被破坏的实在是太厉害了,马小桃的黑色凤凰火焰足足灼烧了一分多钟才消失.如果不进行修补,已经没法再继续比赛了.此时正由几位实力不俗的土系魂师快速修复着.自从进入史莱克学院之后,他们一直都在紧张的学习和修炼,哪有什么放松的时间.凌落宸的疑问则只是落在霍雨浩一个人身上,"极致之冰?"贝贝心中早有定计,低声道:"第一场我们赢了,我们就已经处于主动之中.我们现在最希望出现的.是第二场他们在冲动之下派出两名魂王,或者

滦谇淋坌招r6un44y803l1xog9y18

求收藏.求推荐票.求会员点击.刺入他额头的青色噬灵刻刀轻微震颤,奇异的是,那破入的创口并没有鲜血流出,反而是那噬灵刻刀竟然缓缓软化,化为青碧色的液体顺着那创口流入霍雨浩头部之中.霍雨浩呵呵一笑,道:"发现就发现呗,王冬,你现在是不是觉得特别虚弱,一点力气都用不出来啊?""战争最后虽然胜利了,但我们唐门暗器的作用也受到了极大的质疑.从那以后,各国开始大幅度削减对我们制作暗器的采购.而我们唐门赚钱虽然不少,但按照第一代门主的意思,大部分收入全都捐赠了出去.用来改善穷苦地区的平民生

debian配置snmp团体名

SSH登陆进去中文显示乱码dpkg-reconfigure locales选择了en_US.UTF-8 .zh_CN.GB2312默认选择 zh_CN.GB2312 (如果默认选项没有就选zh_CN)切换到普通用户家目录在.bashrc最后增加:export LC_ALL=zh_CN.GB2312 vi /etc/apt/sources.list  将#注释掉deb cdrom:[Debian GNU/Linux 7.0 _Kali_ - Official Snapshot amd64 LIVE