Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Float, comma as decimal separator and trailing 0

By
aydunno
on 12/1/15, 6:48 AM 1,071 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.

1

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/1/15, 9:55 AM

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

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.

aydunno
on 12/1/15, 2:47 PM

The answer is updated to include the trailing zeros part

Axel Mendoza
on 12/1/15, 3:21 PM

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.
aydunno
on 12/2/15, 3:55 AM

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

aydunno
on 12/2/15, 3:57 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/1/15, 6:48 AM
Seen: 1071 times
Last updated: 12/2/15, 3:56 AM