I have to call the python function in the xml script function. i tried rpc, but i can't use rpc in xml.
Is there any solution for this?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I have to call the python function in the xml script function. i tried rpc, but i can't use rpc in xml.
Is there any solution for this?
If I understand you correctly, there are several ways you could achieve this.
You could use eval in an xml field, for example:
[field name="field_name" model="model.name" eval="obj().env.ref('name')._method_name()"/]
Alternatively you could use a function record in xml, see example below taken from the product module product_demo.xml (https://github.com/odoo/odoo/blob/15.0/addons/product/data/product_demo.xml#L204):
[function model="ir.model.data" name="_update_xmlids"]
[value model="base" eval="[{
'xml_id': 'product.product_product_1_variant_1',
'record': obj().env.ref('product.product_product_1_product_template')._create_product_variant(obj().env.ref('product.product_1_attribute_1_value_1') + obj().env.ref('product.product_1_attribute_2_value_1')),
'noupdate': True,
}, {
'xml_id': 'product.product_product_1_variant_2',
'record': obj().env.ref('product.product_product_1_product_template')._create_product_variant(obj().env.ref('product.product_1_attribute_1_value_1') + obj().env.ref('product.product_1_attribute_2_value_2')),
'noupdate': True,
},]"]
[/function]
My advice is to look at demo data from Odoo modules to find something that resembles your problem. and use this to achive what you want. I hope this answers your question.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
0
Apr 24
|
454 | ||
|
1
Apr 24
|
711 | ||
|
1
Dec 22
|
43371 | ||
|
0
Apr 21
|
2197 | ||
|
3
Nov 19
|
2852 |