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的更多相关文章

  1. odoo 基于SQL View视图的model类

    在做odoo的过程中,会涉及到多表的查询, 尤其是做报表的时候这种情况更甚,这样下来会做很多的关联,不是很方便.odoo提供了一种机制,即基于视图的model类.代码地址在这里. 具体过程如下: 1. ...

  2. odoo 开发基础 -- 视图之xpath语法

    odoo 视图函数 在整个项目文件中,结构并不是十分明显,虽然它也遵循MVC设计,类比django的MTV模式,各个模块区分的十分明显,在Odoo中,视图的概念不是特别明显,很多时候,我们会将调用模型 ...

  3. ODOO里视图开发案例---定义一个像tree、form一样的视图

    odoo里视图模型MVC模式: 例子:在原来的视图上修改他: var CustomRenderer = KanbanRenderer.extend({ ....});var CustomRendere ...

  4. (04)odoo视图操作

    -----------------更新时间19:04 2016-09-29 星期四11:17 2016-09-18 星期日18:13 2016-04-05 星期二15:05 2016-03-14 星期 ...

  5. odoo打包下载

    view 视图中下载按钮的编辑 <record id="action_download_zip" model="ir.actions.server"> ...

  6. odoo看板笔记

    案例0001 odoo中看板使用 #其中一定要many2one阶段字段名称 stage_id <kanban default_group_by="stage_id"> ...

  7. 【odoo14】第十五章、网站客户端开发

    odoo的web客户端.后台是员工经常使用的地方.在第九章中,我们了解了如何使用后台提供的各种可能性.本章,我们将了解如何扩展这种可能性.其中web模块包含了我们在使用odoo中的各种交互行为. 本章 ...

  8. Pyhton开源框架(加强版)

    info:Djangourl:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC)风格的 ...

  9. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

随机推荐

  1. [荐]SWFObject 2最新版语法调用示例

    我一直都在用SWFObject 插入flash,好处多多,代码简洁,不会出现微软的“单击此处以激活控件”的提示(据可靠消息,这个是微软惹的官司,其结果是害苦了用户).不过先前的 调用方法着实有些繁琐, ...

  2. Windows系统上安装多个版本jdk,修改环境变量不生效

    本机已经安装了jdk1.6,而比较早期的项目需要依赖jdk1.5,于是同时在本机安装了jdk1.5和jdk1.6. 安装jdk1.5前,执行 java -version 得到java version ...

  3. JDK中的设计模式

    Creational(创建模式) Abstract factory: 创建一组有关联的对象实例.这个模式在JDK中也是相当的常见,还有很多的framework例如Spring.我们很容易找到这样的实例 ...

  4. 什么是好的API设计?(转)

    什么是API? 我们只要是在进行编程我们就需要不停的设计API. API简单来讲可以是一个调用的函数,一个接口. 抽象来说,接口是一个内聚系统暴漏给外部的一切信息,包含但不限于: 调用方式:比如通过l ...

  5. 在Salesforce中以PDF的格式显示对应的页面

    在Salesforce中可以简单设置page的属性让页面以pdf的方式显示内容, 当然了我们的page内容可以用Html的方式编写 设置方式为:renderAs="pdf" 请看如 ...

  6. HDU 5919 Sequence II 主席树

    Sequence II Problem Description   Mr. Frog has an integer sequence of length n, which can be denoted ...

  7. 模仿QQ左滑删除

    需求: 1.左滑删除 2.向左滑动距离超过一半的时候让它自动滑开,向右滑动超过一半的时候自动隐藏 3.一次只允许滑开一个item 还有,根本不需要自定义view来实现,谨防入坑 布局: <?xm ...

  8. Uva674 完全背包求方案数

    记忆化搜索.注意输入n的位置,否则Tle. dp[i][j]表示用前j种硬币组成i分钱时的种类数 那么状态转移方程是:dp[i][j]+=DP(i-k*v[j],j-1) #include<io ...

  9. Oracle 创建表空间一边串过程

    1.打开SQL Plus,根据提示输入用户名密码登录. 注意:如果是系统用户的话,只能用sysdba登录.例如:sys as sysdba,输入User的密码进行登录. 2.登录成功后,首先创建表空间 ...

  10. shinydashboard包---为shiny提供BI框架

    1.安装 install.packages("shinydashboard") 2.基础知识 仪表盘有三个部分:标题.侧边栏,身体.下面是最最小的仪表面板页面的UI: ## ui. ...