Hassan ALi
Hassan ALi

Reputation: 1331

How to add a field with the sum python function in a Qweb Report?

I am trying to inherit Qweb Report. I am successful in inserting static values inside my qweb Report but when I try to add some computed module it doesn't show me the values.

<odoo>
    <data>
        <template id="delivery_order_report" inherit_id="stock.report_picking">
            <xpath expr="//table[@id='mytable']" position="inside">
                <tfoot>
                    <tr>
                        <td>sum</td>
                        <td><t t-esc="sum([o.pack_operation_ids.pack_lot_ids.qty for o in docs])" /></td>
                    </tr>
                </tfoot>
            </xpath>
        </template>
    </data>
</odoo>

You can see my code my inheriting qweb report of model named as stock.report_picking. When I have tried to fetch o.origin it showed me the field successfully . Below is the code:

<odoo>
    <data>
        <template id="delivery_order_report" inherit_id="stock.report_picking">
            <xpath expr="//table[@id='mytable']" position="inside">
                <tfoot>
                    <tr>
                        <td>sum</td>
                        <td><t t-esc="o.origin" /></td>
                    </tr>
                </tfoot>
            </xpath>
        </template>
    </data>
</odoo>

Upvotes: 0

Views: 1034

Answers (1)

ChesuCR
ChesuCR

Reputation: 9640

You have a wrong python expression. Try this:

<t t-set="result" t-value="0" />
<t foreach="o.pack_operation_ids" t-as="pack" >
    <t t-set="result" t-value="result + sum([x for x in pack.pack_lot_ids.mapped('qty')])" />
</t>
<t t-esc="result" />

Upvotes: 1

Related Questions