Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3587 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
apr 24
1286
1
apr 24
1516
1
dic 22
44927
0
apr 21
3257
3
nov 19
3694