تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
758 أدوات العرض

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
يوليو 24
1747
1
مايو 24
2505
0
نوفمبر 22
2468
1
نوفمبر 22
4818
2
يوليو 22
3555