Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
828 Widoki

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!

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lip 24
1871
1
maj 24
2591
0
lis 22
2531
1
lis 22
4927
2
lip 22
3663