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

Decimal precision in ORM

By
Lucas Huber
on 9/14/15, 5:10 AM 1,257 views

I would like to include a related field from res.currency in a ORM model, but can't find any information how to deal with decimal precision in ORM.

exchange_rate = fields.Float('res.currency.rate', 
'Exchange Rate', related='currency_id.rate',         readonly=True)

When I open a view with the fields I get this error:

 File "/opt/odoo/odoo-server/openerp/tools/float_utils.py", line 29, in _float_check_precision

return 10 ** -precision_digits
TypeError: bad operand type for unary -: 'str' 

Would be glad to know a workaround to solve this problem.


1

Axel Mendoza

--Axel Mendoza--
10263
| 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 9/14/15, 10:41 AM

as docs saids in 

https://www.odoo.com/documentation/8.0/reference/orm.html

class openerp.fields.Float(string=None, digits=None, **kwargs) 
The precision digits are given by the attribute
        Parameters digits -- a pair (total, decimal), or a function taking a database cursor and returning a pair (total, decimal)

Your definition could be changed to this:

exchange_rate = fields.Float('res.currency.rate', 'Exchange Rate', related='currency_id.rate', readonly=True, digits=(16,2))

or you could use a managed decimal precision already defined like 

import openerp.addons.decimal_precision as dp
...
exchange_rate = fields.Float('res.currency.rate', 'Exchange Rate', related='currency_id.rate', readonly=True, digits=dp.get_precision('Account') )

Thank you Axel, Your solution will probably work only with not related fields. In my case I get with both solutions a "duplicate value for keyword arguments "digits"" Error.

Lucas Huber
on 9/14/15, 12:17 PM

related fields are function fields and they need pretty much all the required attributes/arguments for field definition than normal fields, because when it gets calculated the field continue as the normal field type float and needs the digits param

Axel Mendoza
on 9/14/15, 12:22 PM

solved?

Axel Mendoza
on 12/23/15, 3:06 PM

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

1 follower(s)

Stats

Asked: 9/14/15, 5:10 AM
Seen: 1257 times
Last updated: 9/14/15, 10:42 AM