Skip to Content
Menu
This question has been flagged

Hi, 


Hosting Variants: All Odoo hosting variants (Odoo SAAS, Odoo.SH, Odoo onPrem)

Versions: Odoo 15.0, Odoo 16.0 (other versions not tested)

App: Studio


Description: 

I try to create a dynamic domain using Studio but constantly receive a "Domain not properly formed" error. 

I have a field named "x_studio_species" which records the species of a record (e.g. "Cat"). 

I have a second field named "x_studio_shelter_box" which records the shelter/box where an animal is located (e.g. Shelter 1: Box 2). 

Both fields are their own models. The model for the shelter_box has a many_to_many (m2m) field named "x_studio_suitable_for" and records the species for which this box is suitable for (e.g. Shelter 1: Box 2 is suitable for Cats, Dogs, and Birds but Shelter 1: Box 1 is suitable only for Dogs). 


Suppose I'm trying to create a domain in Studio for the Animal form which selects only those boxes suitable for the selected species. Thus it should be a dynamic domain that should look like this: 


[["x_studio_suitable_for","like",x_studio_species]]


This however doesn't work, as you can't save the domain that way. It automatically creates it like this: (see quotes for x_studio_species")

[["x_studio_suitable_for","like","x_studio_species"]]


Thus the domain is created with a string instead of a variable. If I'm removing the quotes manually in the window, I get the message "Domain not properly formed"


How can I create a dynamic domain in Studio? ​Is this a bug and if so, is there a workaround?


Thanks in advance

Avatar
Discard
Author Best Answer

Hi again, 


Well I finally found the solution. 

When looking at the XML code that gets generated, it looks like this: 

   


So the domain is between double quotes and the respective fields are escaped double-quotes. 


By changing the XML-code of it to: 

   


It works perfectly. The domain is between double quotes but the fields themselves are between single quotes and the variable doesn't have any quotes and is recognized as a variable and not as a string. 


The only downside: I cannot modify the domain using the domain-wizard as this is not parsed correctly now. The form and domain are working correctly though. 



Solution: To create dynamic domains, generate the domain as desired, go (using debug-mode) to the XML file in "View" and modify the escaped double quotes " to ' (single quote). 

Avatar
Discard

Indeed, this worked for me. I tried to directly write the field name without single quote (') and it worked

Best Answer

Thanks a lot. I spent a lot of time before I found your answer and it also worked for me.

At the start I had " almost everywhere in my domain, then I changed according to your explanation and now it works perfectly.



Great.

Avatar
Discard
Best Answer

Hi, you can follow this: https://youtu.be/f3mq5fHRPT0

Hope it helps, Thanks

Avatar
Discard
Related Posts Replies Views Activity
0
Jun 24
953
2
Oct 16
7074
2
Jun 22
6899
1
Jul 21
2116
2
Feb 16
3667