Skip to Content
Menu
This question has been flagged
2 Replies
3218 Views

Hi I want to do calculation in py file and return that calculation in a specific field in report.

like,

def do_calc(self):

a=b+c+d

return a


In xml file,

i want to get calculatin done in do_calc.

Avatar
Discard
Best Answer

hello

you can call the method from the xml

like

see the below link: 

from xml call method like here call the method get_months : 

<t t-foreach="get_months" t-as="month"> (you can use <span t-esc="method_name"/> also for print the data on report.)

https://github.com/odoo/odoo/blob/12.0/addons/hr_holidays/report/hr_holidays_templates.xml#L18


into .py render method. so from xml access the key 'get_months' and from that call the method. and from that self._get_method is doing the calculation(as per your need.)

from dictionary ket it call the method like =>  'get_months': self._get_months(data['form']['date_from']),

https://github.com/odoo/odoo/blob/12.0/addons/hr_holidays/report/holidays_summary_report.py#L123

Avatar
Discard
Best Answer

Hi Akshay,

You can write code like:

<t t-set="total_value" t-value="o.do_calc()"/>

<t t-esc="total_value"/>

Here o means self(current object) or you can use any model's method like 

<t t-set="total_value" t-value="request.env['model.name'].do_calc()"/>


 Hope it will helpful for you.


Thanks and regards

Haresh Kansara

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 24
160
0
Aug 24
166
0
Jan 24
735
1
Nov 23
419
0
Jun 23
971