Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
as docs saids in
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') )
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 9/14/15, 5:10 AM|
|Seen: 1935 times|
|Last updated: 9/14/15, 10:42 AM|