Odoo 8:Many2many域过滤器 [英] Odoo 8: Many2many domain filter

查看:80
本文介绍了Odoo 8:Many2many域过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几种具有多对多关系的组织类型,其中描述了哪些类型可能是其他类型的父级(例如,部门可以是子部门和工作组的父级).这不是严格的层次结构(工作组可以是其他工作组的父级),因此存在many2many关系.

I have several organization types with a many2many relation describing which types that may be parent to other types (e.g. department can be parent to sub-department and working group). It's NOT a strict hierarchy (working group can be parent to other working groups), hence the many2many relation.

我的organization_type对象上有两个字段:allowed_parent_type_ids和倒数allowed_children_type_ids.

I have two fields on my organization_type object: allowed_parent_type_ids and the inverse allowed_children_type_ids.

现在,我想根据组织对象的父项来限制组织类型字段,因此部门"的子级只能选择允许作为部门子级的组织类型,等等.

Now I want to restrict the organization type field on my organization object depending on it's parent, so a child of a "department" can only select the organization types allowed to be children of departments and so on.

在表单视图中,我尝试过:

In my form view, I tried:

<field
    name="organization_type_id"
    domain="[('id', 'in', parent_id.organization_type_id.allowed_children_ids)]"
    />

我也尝试在我的组织对象上放置一个带有允许类型的相关字段,但是我总是会收到一条错误消息. 我最后的尝试是:

I also tried to put a related field with allowed types on my organization object, but I always ends up with an error message. My last attempt was:

domain=[('id', 'in', allowed_type_ids)]

给出错误消息:

TypeError: not all arguments converted during string formatting

客户端实际上获取了一个像"allowed_type_ids" = [0,1,2]的JSON对象,如果我将域表达式中的allowed_type_ids替换为[0,1,2],就没有错误,并且在选择中得到了三种组织类型...

The client actually fetches a JSON object like "allowed_type_ids" = [0,1,2] and if I replace allowed_type_ids in the domain expression with [0,1,2] there are no errors and I get the three organization types in my selection...

推荐答案

尝试一下:

<field
    name="organization_type_id"
    domain="[('id', 'in', parent_id.organization_type_id.allowed_children_ids.ids)]"
    />

allowed_children_ids是一组记录,而allowed_children_ids.ids是这些记录的ID列表.

While allowed_children_ids is a set of records, allowed_children_ids.ids is a list of ids of those records.

您也可以从另一侧进行处理.这应该可以工作,并且事件发生速度更快:

You can also approach this from the other side. This should work and be event faster:

<field
    name="organization_type_id"
    domain="[('allowed_parent_type_ids', '=', parent_id.organization_type_id)]"
    />

这篇关于Odoo 8:Many2many域过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆