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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
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
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up