我正在寻找一种方法来过滤后续选择,具体取决于填充的内容。 我想要一个树状结构来设置位置,例如:
=>国家
==>状态
===>区
因此,假设您首先进入区域,则在其他两个区域中只有一个选择。 假设您先进入该国,那么后两种选择就比较有限。
我知道我应该处理many2one字段,但此时我能做的就是将多个选项变为可见/不可见,这是非常低效的。
我对Odoo还是很陌生,并且发现文档有些缺乏。任何帮助将不胜感激!
答案 0 :(得分:0)
我将使用运算符many2one
来处理=?
字段和域
例如:
class MyModel(models.Model):
_name = "my.model"
country_id = fields.Many2one(comodel_name="res.country")
state_id = fields.Many2one(comodel_name="res.country.state")
disctrict_id = fields.Many2one(comodel_name="res.country.state.district")
我不知道型号名称是否正确,但是您应该已经知道它们。
在视图中,将域与提及的运算符一起使用:
<field name="country_id"
domain="[('state_ids', '=?', state_id),('state_ids.district_ids', '=?', district_id)]" />
<field name="state_id"
domain="[('country_id', '=?', country_id),('district_ids', '=?', district_id)]" />
<field name="disctrict_id"
domain="[('state_id', '=?', state_id),('state_ids.country_id', '=?', country_id)]" />
我没有对那些AND条件/域进行任何测试。而且我不知道这三个模型的结构。我的假设是,在one2many
-> many2many
和res.country
-> res.country.state
上存在res.country.state
或res.country.state.district
关系。