[英]Domain in Many2one Odoo 11
I have three models 我有三种模式
class ZohoTags(models.Model):
_name = 'zoho.tags'
name = fields.Char(string="Tags")
tag_id = fields.Char(string="Tag Id")
class TagsLine(models.Model):
_name = 'zoho.tags.line'
x_zoho_tags = fields.Many2one('zoho.tags', string='Tags')
x_tags_option = fields.Many2one('zoho.tag.option', string='Tags Option', domain="[('tag_ids', '=', x_zoho_tags.tag_id)]")
rules_id = fields.Many2one('hr.salary.rule')
class TagOptions(models.Model):
_name = 'zoho.tag.option'
name = fields.Char(string="tag option name")
option_tag_id = fields.Char(string="tag option id")
tag_ids = fields.Char(string="tag_id")
In the zoho.tags
model, I have a field called tag_id
and in the zoho.tag.option
, I have tag_ids
and both are having the same values. 在
zoho.tags
模型中,我有一个名为tag_id
的字段,在zoho.tag.option
,我有tag_ids
并且两者都具有相同的值。
In the zoho.tags.line
model, I have a Many2one
field called x_zoho_tags
, which shows a list of tags like: division, state, etc.
and x_tags_option
, which shows options for each tag, such as: 在
zoho.tags.line
模型中,我有一个名为x_zoho_tags
的Many2one
字段,该字段显示标签列表,例如: division, state, etc.
以及x_tags_option
,其中显示每个标签的选项,例如:
Tag (division) has options (A,B,C) and these options are having the same
tag_ids
stored for (division) tag标签(分区)具有选项(A,B,C),并且这些选项具有与(分区)标签相同的
tag_ids
I want to add a domain to x_tags_option
in order to filter x_tag_option
to show only options that are having the same tag_id
. 我想向
x_tags_option
添加域,以便过滤x_tag_option
仅显示具有相同tag_id
选项。
So when I select division
from x_zoho_tags
, then x_tags_option
should show only A, B and C
. 因此,当我从
x_zoho_tags
选择division
时,则x_tags_option
应该仅显示A, B and C
I have tried to add this line below, but it does not work 我试图在下面添加此行,但是它不起作用
domain="[('tag_ids', '=', x_zoho_tags.tag_id)]
I have figure it out. 我知道了。 This is how I have done it:
这是我的方法:
In python: 在python中:
@api.onchange('x_zoho_tags')
def onchange_tags(self):
res = {}
if self.x_zoho_tags:
res['domain'] = {'x_tags_option': [('tag_ids', '=', self.x_zoho_tags.tag_id)]}
return res
In XML: 在XML中:
<field name="x_zoho_tags"/>
<field name="x_tags_option" onchange="onchange_tags(x_zoho_tags)"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.