콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
522 화면

I have the following product unit prices:

10.00

12.375

15.4755

How can I show JUST the number of decimals in the amount?

If it is 2, I want to show 2.

If 3 or 4, show 3 or 4.

I don't want EVERY price to show the same number of decimals.

Is this possible?

아바타
취소
베스트 답변

You will want to override how Odoo shows the data in the td_price_unit cell of the Invoice Lines:


Instead of this:

<td name="td_price_unit">
    <span class="text-nowrap" t-field="line.price_unit">9.00</span>
</td>


Do something like this:

<td name="td_price_unit">
    <t t-set="decimals"
       t-value="max(2, len(str(line.price_unit).split('.')[1]) if '.' in str(line.price_unit) and len(str(line.price_unit).split('.')) > 1 else 2)"/>
    <span class="text-nowrap" t-esc="('{:.' + str(decimals) + 'f}').format(line.price_unit)">9.00</span>
</td>

Note: the complex calculation ensures you never drop below 2 digits, so $10 even will show always as 10.00.


아바타
취소
관련 게시물 답글 화면 활동
1
4월 16
4196
1
6월 15
3915
0
3월 15
3291
Decimal precision 해결 완료
3
6월 24
50740
1
12월 19
4086