Skip to Content
Menu
This question has been flagged
2 Replies
1934 Views

Hi,

We use odoo 11.

I want the field value to be the amount after entering it by the user ;  convert the last three digits to zero.


from math import log  

    amount = fields.Float(string="Amount",   compute=' _lastzero ' ,required=True)


@api.multi   

def _lastzero(self): 

      digits=3        

expo = 10**(int(math.log(self.amount, 10)) -digits+1)          

      return expo * (self.amount // expo)

ValueError: math domain error

Avatar
Discard
Best Answer

Change

from math import log

to

import math


Avatar
Discard
Best Answer

there are some issues
1) math domain error raise when you try to get a log of a negative amount
2) compute fields could not return anything like a function. you have to value of the field inside a function
     llike
     self.amount = # your expression
3) by default compute field is not stored so  amount value should be store some other field 

Avatar
Discard