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

How can we format values on Qweb reports to only drop the trailing 0's after the decimal poing in Qweb v8 reports?  Such that 1.0000 would display as 1, 1.5000 would display as 1.5, and 1.5250 would display as 1.525?

Can it be a modification to formatLang(<<your value>>,digits=0)

I want my quantities in Quotes/Sales Orders/Invoice reports to appear like this https://www.purekarting.com/odoo/lightspeedinvoice.pdf instead of how they are currently like this https://www.purekarting.com/odoo/sale.report_saleorder.pdf

아바타
취소
베스트 답변

Qweb allows you to run python expressions using t-esc and t-raw tags. This should therefore work: 

t-esc="int(float(l.quantity))"

I hope this helps.

아바타
취소
베스트 답변

Don't believe there is code to do that.  You will probably need to write some code to handle the special formatting you require.

How about trying this piece of coding based on the text of your question/answer:

<t t-set="mod_qty">
    formatLang(l.product_uom_qty, digit=0)
</t>

<t t-if="mod_qty == l.product_uom_qty">
    <t t-esc="mod_qty" />
</t>

<t t-if="mod_qty != l.product_uom_qty">
    <t t-esc="(l.product_uom_qty * 1)" />
</t>

Or this generic code that will print your list of numbers.

<t t-foreach="[3.000, 3.050, 3.005, 3.0005]" t-as="my_qty">
    <t t-set="mod_qty">
        formatLang(my_qty, digit=0)
    </t>

    <t t-if="mod_qty == my_qty">
        <p><t t-esc="mod_qty"/></p>
    </t>

    <t t-if="mod_qty != my_qty">
        <p><t t-esc="(my_qty * 1)"/></p>
    </t>
</t>

아바타
취소
작성자 베스트 답변

I've gotten closer.

https://www.purekarting.com/odoo/sale.report_saleorder_closer.pdf

By using <t t-esc="(l.product_uom_qty * 1)" />, it converts the qty from a string to a number.  Trailing zeros past the first decimal precision are dropped in numbers.

So, seeing as how I have decimal precision set to 3 on product_uom_qty, values will be reported as:

3.000 prints as 3.0
3.050 prints as 3.05
3.005 prints as 3.005
3.0005 is rounded up by Odoo to 3.001, and then prints as 3.001

Close but not perfect.  I'd like to drop that trailing .0 from the whole number quantities still.

아바타
취소

Why not handle that case in an if statement. Test to see if you have a whole number and then use formatLang to remove the zeros just for whole numbers. Seems you have everything else covered.

작성자

Any idea how to check if whole number? IF WHOLE IF NOT THEN THIS FOR w/ Decimals I've also ready through this: https://www.odoo.com/documentation/master/reference/qweb.html There is simply no detailed documentation on writing the conditionals. I also wonder if the decimal trim can't just be done with a t-field-options setting, in the same way we format date fields on reports. However, I can't find the documentation explaining the t-field-options which are available for each specific field. From the Qweb documentation: t-field-options can be used to customize fields, the most common option is widget, other options are field- or widget-dependent.

why cant you truncate it to a whole number in formatLang then test it against the original value. If they are equal then it is a whole number and you print the truncated number if not then you print your formatted decimal.

I have updated my answer above. Give that a try.

베스트 답변

what you could  do is :

import openerp.addons.decimal_precision as dp

and also  for example this will allow your field to acces the decimal accuary of account so if you set account to have 8 decimal places your field will have 8 decimal places:

'rent':fields.float('Rent',digits_compute= dp.get_precision('Account')), 

 

 

 

아바타
취소
관련 게시물 답글 화면 활동
3
3월 18
7856
1
5월 24
2953
0
7월 17
3546
1
4월 25
1044
2
3월 25
1167