我有三个模型
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")
在 zoho.tags
模型中,我有一个名为 tag_id
的字段,在 zoho.tag.option
中,我有 tag_ids
并且两者具有相同的值。
在 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
我想向 x_tags_option
添加域以过滤 x_tag_option
仅显示具有相同 tag_id
的选项。
因此,当我从 x_zoho_tags
中选择 division
时,x_tags_option
应仅显示 A、B 和 C
。
我尝试在下面添加这一行,但它不起作用
domain="[('tag_ids', '=', x_zoho_tags.tag_id)]
最佳答案
我已经弄清楚了。我就是这样做的:
在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
在 XML 中:
<field name="x_zoho_tags"/>
<field name="x_tags_option" onchange="onchange_tags(x_zoho_tags)"/>
关于python - Many2one Odoo 11 中的域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55206659/