How can I use an XML id as a reference in a field domain?

Asked by Numérigraphe

I'd like to create a module that loads a CSV file of partner categories, and another one that adds a new many-to-one field for a category in the partner, and let users it's value only among the categories of the first module.

I tried to restrict the domain with this but it didn't work :
     <field name="ape_id" domain="[('parent_id','child_of', ref('...other_module.xml_id...'))]"/>
The client prints this to STDOUT:
ERROR:tools.expr_eval:[('parent_id','child_of', ref(...other_module.xml_id...))]
Traceback (most recent call last):
  File "/home/ls/Sources/openerp/trunk/client/bin/tools/__init__.py", line 52, in expr_eval
    temp = eval(string, context)
  File "<string>", line 1, in <module>
TypeError: 'bool' object is not callable

Any idea how I can achieve this?
Lionel.

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Francois Degrave (fde-be) said :
#1

Hi!

Never tried this, but mybe somthing like "[('parent_id','child_of', %(other_module.xml_id)d)]" would work, just like action buttons?

Revision history for this message
Craig Gowing (credativ) (craiggowing) said :
#2

That works a treat, thanks Francois!

Revision history for this message
Joshua Jan(SHINEIT) (joshuajan) said :
#3

Hi all,

I try like this:
<record id="my_rule" model="ir.rule">
   <field name="xxxx"/>
   <field name="domain_force" eval="[('parent_id','child_of', %(other_module.xml_id)d)]" />
</record>
I get an "SyntaxError: invalid syntax"

And I also try <field name="domain_force">[('parent_id','child_of', %(other_module.xml_id)d)]</field> , but it does`t work.

Best Regards
Joshua

Can you help with this problem?

Provide an answer of your own, or ask Numérigraphe for more information if necessary.

To post a message you must log in.