İçereği Atla
Menü
Bu soru işaretlendi
823 Görünümler

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!

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Tem 24
1869
1
May 24
2590
0
Kas 22
2530
1
Kas 22
4925
2
Tem 22
3658