Search code examples
xmlodooodoo-viewodoo-12

Get value from XML sum="x" in odoo


I am trying to get the sum of product quantities in odoo account.invoice model.

This can be done easily in the XML tree view adding sum= for this field:

But, I also want to have this value printed on the QWeb report (the invoice pdf).

How can I get the sum="" value to be printed on the QWeb report? Or create a new field that returns this value?

I am new to odoo, and I am using odoo studio on SaaS.

I have tried to create a new field with compute code, but it is not working.

Here is the code I tried with a new float field "x_studio_total_qty" in account.invoice model:

for record in self:
 record.x_studio_total_qty = len(record.quantity)

dependencies: invoice_line_ids.quantity

But the x_studio_total_qty value stays 0.00.

Thanks for the help

Maxime


Solution

  • The code should be:

    for record in self:
        record['x_studio_total_qty'] =\
            sum([line.quantity for line in record.invoice_line_ids])
    

    If sum is not working (never tested it) just try it without using it:

    for record in self:
        total = 0.0
        for line in record.invoice_line_ids:
            total += line.quantity
        record['x_studio_total_qty'] = total