This question has been flagged
2 Replies
10077 Views

Hello all,

On the template sale.report_saleorder_document in Odoo 10 enterprise.

One line causes an error, and I don't find the problem. It is weird because this line works on an other Odoo 10 installation.

These lines works well :

<span t-field="l.price_subtotal" t-options='{"widget": "monetary", "display_currency": doc.pricelist_id.currency_id}' />
<span t-field="l.price_total" t-options='{"widget": "monetary", "display_currency": doc.pricelist_id.currency_id}' />
<span t-esc="subtotal" t-options="{'widget': 'monetary', 'display_currency': doc.pricelist_id.currency_id}" />

But this one doesn't work :

<span t-esc="amount_by_group[1]" t-options="{'widget': 'monetary', 'display_currency': doc.pricelist_id.currency_id}" />

I get this error :

QWebException: unsupported operand type(s) for /: 'unicode' and 'float'
Traceback (most recent call last):
  File "/opt/odoo/addons/base/ir/ir_qweb/qweb.py", line 315, in _compiled_fn
    return compiled(self, append, values, options, log)
  File "<template>", line 1, in template_sale_report_saleorder_document_1191
  File "<template>", line 3, in body_call_content_1190
  File "<template>", line 136, in foreach_1172
  File "/opt/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 276, in _get_widget
    content = converter.value_to_html(value, field_options)
  File "/opt/odoo/addons/base/ir/ir_qweb/fields.py", line 322, in value_to_html
    formatted_amount = lang.format(fmt, display_currency.round(value),
  File "/opt/odoo/addons/base/res/res_currency.py", line 93, in round
    return tools.float_round(amount, precision_rounding=self.rounding)
  File "/opt/odoo/odoo/tools/float_utils.py", line 52, in float_round
    normalized_value = value / rounding_factor # normalize
TypeError: unsupported operand type(s) for /: 'unicode' and 'float'
Error to render compiling AST
TypeError: unsupported operand type(s) for /: 'unicode' and 'float'
Template: sale.report_saleorder_document
Path: /templates/t/t/div/div[3]/div/table/t/tr/td[2]/span
Node: <span t-esc="amount_by_group[1]" t-options="{'widget': 'monetary', 'display_currency': doc.pricelist_id.currency_id}"/>
Avatar
Discard
Best Answer

Hi,

Please check the values returned by _get_tax_amount_by_group , I think ie unicode or string, not float.

this is the code that fetches amount_by_group

<t t-foreach="o._get_tax_amount_by_group()" t-as="amount_by_group">    ...


python function _get_tax_amount_by_group() returns;

res = map(lambda l: (l[0].name, formatLang(self.env, l[1], currency_obj=currency)), res)
return res
Avatar
Discard
Author

Thanks for your precious answers! Have a good day!

Author Best Answer

In my Odoo 10 on which I do my tests :

We have this in account_invoice and sale_order _get_tax_amount_by_group :

res = map(lambda l: (l[0].name, l[1]), res)

So, these lines work well in sale orders and invoices :

<span t-field="doc.amount_total" t-options='{"widget": "monetary", "display_currency": doc.pricelist_id.currency_id}' />
<span t-esc="amount_by_group[1]" t-options='{"widget": "monetary", "display_currency": o.currency_id}' />


On the Odoo 10 enterprise of my customer, the code in Python is not the same, we have this line in account_invoice and sale_order _get_tax_amount_by_group :

res = map(lambda l: (l[0].name, formatLang(self.env, l[1], currency_obj=currency)), res)

So, like mister Hilar said, this line will be sufficient in sale orders and invoices PDF report :

<span t-esc="amount_by_group[1]"  />
Avatar
Discard