Skip to Content
Menu
This question has been flagged
5 Replies
3027 Views

I want to print several id of a table but I get an error and I think it is because I try to show a computed field. I can only print one id at a time and not all. The error that appears is the following:

Error to render compiling AST ValueError: Expected singleton: project_rc.account (3, 4) Template: 252 Path: / templates / t / t / t / t / div / table / tfoot / tr [1] / th [2] / span Node: t-esc = "i.total_account_debit" />

The code is the following:

        <t t-call = "web.html_container">

            <t t-foreach = "docs" t-as = "i">

                <t t-call = "web.external_layout">

                    <div class = "page">

                 <t t-foreach = "i.detail_document_ids" t-as = "o">

                                <tr>

                                    <td>

                                        <span t-esc = "o.date" />

                                    </td>

                                    <td>

                                        <span t-esc = "o.razon_social_id.name" />

                                    </td>

                                    <td>

                                        <span t-esc = "o.total_debit" />

                                    </td>

                                    <td>

                                        <span t-esc = "o.total_credit" />

                                    </td>

                                </tr>

                            </t>

                            <tfoot>

                                <tr> <th colspan = "2" style = "text-align: center"> Total </th>

                                    <th style = "text-align: center"> <span t-esc = "i.total_account_debit" /> </th>

                                    <th style = "text-align: center"> <span t-esc = "i.total_account_credit" /> </th> </tr>

                                 <tr> <th colspan = "2" style = "text-align: center"> Balance </th>

                                  <th colspan = "2" style = "text-align: center"> <span t-esc = "i.balance" /> </th> </tr>

                            </tfoot>

table "account" py

title = fields.Char (string = "Name")

total_account_debit = fields.Float (string = "Total account must", compute = "_ total_account_debit")

total_account_credit = fields.Float (string = "Total account have", compute = "_ total_account_credit")

balance = fields.Float (string = "Balance", compute = "_ balance")


Avatar
Discard
Best Answer

you need to use jinja2

for example:
% for payment in object.payment_ids:

     <tr>

          <td>

               ${payment.journal_id.name}

          </td>

          <td>

               ${payment.payment_date.strftime("%d. %B %Y")}

          </td>

          <td>

               <strong style="font-weight:bolder">$${"%.2f" % payment.amount} </strong>

          </td>

     </tr>

% endfor ​

Avatar
Discard
Best Answer

variable `i` contain multiple records so try this and repeat it for  `total_account_credit` and `balance`

<th style = "text-align: center"> <span t-esc = "sum([line.total_account_debit for line in i])" /> </th>


Avatar
Discard
Author

It doesn't work, I still get the error: Error to render compiling AST

ValueError: Expected singleton: project_rc.account (3, 4)

Template: 252

Path: / templates / t / t / t / t / div / table / tfoot / tr [1] / th [2] / span

Node: <span t-esc = "sum ([line.total_account_debit for line in i])" />

what's the output of <t t-esc="i"/> and <t t-esc="i[0]. total_account_debit"/> ?

Author

I worked with that code <t t-esc="i[0]. total_account_debit"/> now I can print several id in a report, thank you very much.

Could you explain to me what function does this do i[0]. ?

Related Posts Replies Views Activity
3
Apr 24
1026
0
May 24
46
1
Apr 24
1833
4
Sep 23
3086
2
Sep 23
5593