This question has been flagged
1 Reply
13168 Views

I created a simple report with float numbers which are calculated beforehand in this simple method:


def onchange_value(self, cr, uid, ids, c1 = 0.0, c2 = 0.00, c3 = 0.0, c4 = 0.0, c5 = 0.0, c6 = 0.0, c7 = 0.0, c8 = 0.0, c9 = 0.0, c10 = 0.0, context = None):

cx = (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9) * 1.19

c10 = round(cx, 2)

return {'value': { 'c10': c10 }}


the numbers aredeclared in this manner:

'c1': fields.float(string="Betrag 1"),

'c2': fields.float(string="Betrag 2"),

'c3': fields.float(string="Betrag 3"),


and added to the report in this manner: 

<div class="col-xs-2"> <p t-field="o.c1" /> </div>   

<div class="col-xs-2"> <p t-field="o.c2" /> </div>

<div class="col-xs-2"> <p t-field="o.c3" /> </div>


What I try to do and actually have no idea how, is:

Having a comma as a decimal sepataor instead of the dot and the trailing zero need to be displayed.

Any help is much appreciated.

Avatar
Discard
Best Answer

For change the decmal separator you can do it in your specific lang on the menu /Settings/Translations/Languages, there is a field called Decimal Separator specifically for that matter

For change the trailing zeros you need to do it directly on the float field by defining the decimal precision like:

Old Api

'rounding': fields.float('Rounding Factor', digits=(12,2)),

New Api

rounding = fields.Float('Rounding Factor', digits=(12,2))

Where (12,2) is the number of digits before and after the decimal separator

Avatar
Discard
Author

you agaibn, thanks!!!!! guess I have to mention you in the credits now :P I will try this out tomorrow. any idea for the trailing zero? My last idea was to modify the downloaded pdf by an external script.

The answer is updated to include the trailing zeros part

Author

got it! remarks on the solution: when trying to accomplish this by changing anything in the code, the leading zero where never displayed, unless using

in stead of field vauel in the report's definition. I solved it by doing both changes in the seetings. 1. the languages settings you pointed out. importatn here is to also change the value of the thousands separator. 2. under settings > technical > database structure > decimal accuracy, create a new entry whith your modules name and the number of digits that should follow the separator. in this way, comma and trainiling zeros are displayed everywhere correctly, especially in the reports.
Author

one part is not displayed: using t-esc="'%.2f'%(o.c2)" instead of t-field value