Skip to Content
Menu
This question has been flagged
1 Atsakyti
183 Rodiniai
      <td style="padding: 0.25rem; vertical-align: middle;">
<!-- <span t-esc="o.line_ids.filtered(lambda line: line.code == 'ETF').mapped('total')[0] if o.line_ids.filtered(lambda line: line.code == 'ETF') else ''"-->
<!-- t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/>-->
<span t-esc="sum(o.line_ids.filtered(lambda line: line.code == 'ETF').mapped('total')"
t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/>

</td>

Those two spans are same span by differentr ways,one is  commented, but error occure,  How can i solve this  , 

*first method error,odoo.addons.base.models.ir_qweb.QWebError: Error while rendering the template:

    ValueError: The value send to monetary field is not a number.

    Template: hr_payroll.report_payslip

    Reference: 1571

    Path: /t/t/div/table[1]/tbody/tr[4]/td[2]/span

    Element: <span t-esc="o.line_ids.filtered(lambda line: line.code == \'ETF\').mapped(\'total\')[0] if o.line_ids.filtered(lambda line: line.code == \'ETF\') else \'\'" t-options="{\'widget\': \'monetary\', \'display_currency\': o.company_id.currency_id}"/>

*second method  error,odoo.addons.base.models.ir_qweb.QWebError: Error while rendering the template:

    ValueError: Can not compile expression: sum(o.line_ids.filtered(lambda line: line.code == 'ETF').mapped('total')

    Template: hr_payroll.report_payslip_lang, How can i solve this? can someone help me?

Portretas
Atmesti

Is it custom code?

Best Answer

Hi,


Try the following code,


<td style="padding: 0.25rem; vertical-align: middle;">

    <span t-esc="sum(o.line_ids.filtered(lambda line: line.code == 'ETF').mapped('total') or [0.0])"

          t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/>

</td>


The issue occurred because the first code version tried to display an empty string when no line with code 'ETF' existed, but the monetary widget in Odoo only accepts numeric values, not text, leading to the “value is not a number” error. The second version failed due to a syntax error caused by a missing parenthesis in the sum() expression. The corrected code uses sum(o.line_ids.filtered(lambda line: line.code == 'ETF').mapped('total') or [0.0]), which safely computes the total by ensuring that if no 'ETF' line exists, it still sums [0.0]. This guarantees a numeric result, avoids rendering errors, and properly formats the output using the monetary widget with the company’s currency. This method is both clean and reliable for use in Odoo’s QWeb reports.


Hope it helps

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
0
spal. 25
218
2
kov. 24
2766
0
vas. 23
1885
1
spal. 25
1936
2
spal. 25
337