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
)

最新文章

  1. (转)linux下和云端通讯的例程, ubuntu和openwrt实验成功(一)
  2. 在EC2上搭建L2TP over IPSec VPN服务器
  3. 解析for循环
  4. 保护模式下GDTR,LDTR,全局描述符表,局部描述符表和选择器的关系
  5. 深入理解jdk和jre(转)
  6. ADS2008 安装方法详解及文件下载
  7. linux下使用vi操作
  8. CentOS 下mysql ERROR&amp;n…
  9. Maven依赖解析
  10. js高阶函数应用—函数防抖和节流
  11. 在IIS中如何配置SSL(https)
  12. Cookie隐藏小广告
  13. springmvc+ajax文件上传
  14. Unity 脚本中的主要函数的 执行顺序及其介绍
  15. 建立TCP连接过程
  16. ShareMemory
  17. js with 语句的用法
  18. NetFPGA-SUME下reference_nic测试
  19. mini2440的程序下载
  20. Qt使用QNetworkAccessManager实现Http操作

热门文章

  1. HDU 3364 Lanterns 高斯消元
  2. linux常用命令和选项
  3. Linux学习笔记(1)Linux虚拟机安装过程中的知识点及常用管理工具
  4. C# 溢出检查
  5. jquery尺寸:宽度与高度
  6. sed 字符串替换
  7. Codeforces Round #334 (Div. 2)
  8. 每天一个linux命令---curl
  9. 每天一个linux命令---tar
  10. React的第一步