forvas
forvas

Reputation: 10189

Is there any way to show a variable using decimal precision in Qweb?

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?

Upvotes: 3

Views: 3449

Answers (2)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

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}'/>

Upvotes: 0

Avani Somaiya
Avani Somaiya

Reputation: 348

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.

Upvotes: 4

Related Questions