跳至内容
菜单
此问题已终结
894 查看

I am currently working on a custom app in Odoo and I am trying to implement a domain filter widget that dynamically updates based on the selection of another field. Specifically, I have a `model_id` field (a Many2one relation to `ir.model`) and I want the domain filter to use the model selected in `model_id`.

Here is the relevant part of my code:

```python

class MyCustomModel(models.Model):

_name = 'my.custom.model'

_description = 'My Custom Model'

model_id = fields.Many2one(

"ir.model",

string="Main Model",

required=True,

tracking=True,

ondelete="cascade",

)

domain = fields.Char(string="Domain Filter", tracking=True, default="[]")

model_name = fields.Char(related='model_id.model', string="Model Name", readonly=True)

```

In my XML view, I have the following fields:

```xml

<field name="model_id"/>

<field name="domain" widget="domain" options="{'model': model_id}" invisible="request_method == 'get'"/>

```

I also tried using the related field `model_name`:

```xml

<field name="model_id"/>

<field name="model_name" invisible="1"/>

<field name="domain" widget="domain" options="{'model': 'model_name'}" invisible="request_method == 'get'"/>

```

However, I am facing issues with passing the selected model to the domain filter widget. The domain filter expects a string, and I am unsure how to correctly reference the selected model from `model_id`.

Has anyone encountered a similar issue or can provide guidance on how to properly implement this functionality? Any help would be greatly appreciated!

Thank you in advance!

形象
丢弃
相关帖文 回复 查看 活动
0
7月 24
1931
1
5月 24
2644
0
11月 22
2575
1
11月 22
5005
2
7月 22
3720