Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
6 Odpowiedzi
17938 Widoki

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.


Awatar
Odrzuć
Najlepsza odpowiedź

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') )

Awatar
Odrzuć
Autor

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.

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

Marked it as solved as this is a good answer that works fine. ;)

Najlepsza odpowiedź

is the error solved?

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sty 23
32445
2
lis 22
7862
0
wrz 19
98
1
lis 18
6213
1
lip 17
4176