Skip to Content
Menu
This question has been flagged
1 Reply
4536 Views

Hi there,

i am looking for a way to write calculated values inside a qweb report xml file to an dynamic array  and read this values at a later step in the xml file.

Any ideas to do this ?

Thanks,

Franz  

Avatar
Discard
Best Answer

Hi Franz,

You actually have quite some options to do this. If you already have the values in the QWeb you can calculate/set them in a variable. An example:

<t t-set="result" t-value="0"/>
<t t-foreach="invoice_lines" t-as="invoice_line"> 
    <t t-set="result" t-value="result + invoice_line.quantity"/>                        
</t>
<span t-esc="result"/>

If you need to do more complex calculations or need to do some extra queries in the backend side you can call a Python function from your Qweb report that returns some values. In QWeb:

<t t-set="dynamic_list" t-value="o.get_dynamic_values()"/>

In the model (Python):

def get_dynamic_values(self):
    invoice_lines = self.env['account.invoice.lines'].search([('partner_id', '=', self.id)])
    # Some complex computations here
    return invoice_lines                                          

Odoo will then return the values from your Python function to the QWeb side and you can use the values from the variable "dynamic_list" then.
Don't forget that QWeb supports the default Python options that are available such as sum(), avg(), [], setting values and so on.    ​

Regards,

Yenthe

Avatar
Discard