Reputation: 2186
How add SUM for etc. id field bottom on table without .py file and function?
<table class="table table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tr>
<t t-foreach="docs" t-as="o">
<tr>
<td><t t-esc="o.id"/></td>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.quantity"/></td>
</tr>
</t>
</tr>
<tr>
<td colspan="3" class="text-right"> SUM (o.quantity) </td>
</tr>
</table>
Is it possible in this situation?
Upvotes: 1
Views: 6157
Reputation: 1675
try below code
<table class="table table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tr>
<t t-foreach="docs" t-as="o">
<tr>
<td><t t-esc="o.id"/></td>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.quantity"/></td>
</tr>
</t>
</tr>
<tr>
<span t-esc="sum(line.quantity for line in docs)"/>
</tr>
</table>
Upvotes: 3
Reputation: 14746
You can create one variable and sum quantity in every loop iteration and print it at last.
So you should try as following :
<table class="table table-condensed">
<t t-set="qty" t-value="0">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tr>
<t t-foreach="docs" t-as="o">
<tr>
<td><t t-esc="o.id"/></td>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.quantity"/></td>
<t t-set="qty" t-value="qty + o.quantity"/>
</tr>
</t>
</tr>
<tr>
<td colspan="3" class="text-right"> <span t-esc="qty"></span> </td>
</tr>
</table>
Upvotes: 2