This question has been flagged
1 Reply
2101 Views

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?

Avatar
Discard
Best Answer

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.

Avatar
Discard