3

I am showing a float variable in a Qweb report:

<t-set="my_qweb_float_variable" t-value="4.0"/>
<span t-esc="'%.4f'% my_qweb_float_variable"/>

I want to round it with the decimal precision of Product Price. I am rounding it to 4 digits because I know that Product Price has a decimal precision of 4 digits, but the right way would be to get the precision value from the record stored in the decimal_precision table, just in case users change it.

Any ideas?

forvas
  • 9,801
  • 7
  • 62
  • 158

2 Answers2

4

You can get decimal_precision table value this way:

<t t-set="decimal_precision" t-value="request.env['decimal.precision'].precision_get('Product Price')"/>

Then when you print the value of decimal_precision variable, it will show the browsable object of decimal.precision model.

And then you can get your field value this way:

<t t-esc="my_qweb_float_variable" t-options='{"widget": "float", "precision": decimal_precision}'/>

I hope this will helps you. Thank you.

forvas
  • 9,801
  • 7
  • 62
  • 158
Avani Somaiya
  • 348
  • 2
  • 7
0

It need integer number for precision value otherwise it will fail.

Following is a example of 2 decimal precision in QWEB report.

Correct:

<t t-esc="my_qweb_float_variable" t-options='{"widget": "float", "precision": 2}'/>

Wrong:

<t t-esc="my_qweb_float_variable" t-options='{"widget": "float", "precision": 2.0}'/>
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58