1
votes

How in function subtraction two float field "Finish - Start"

start = fields.Float(string='Star')
finish = fields.Float(string='Fin')
total = fields.Float(string='Total')

    @api.one
       def total_sum(self):
       ?????? 
2
Can you please get in more detail with your question? It is hard to answer in this broad context.CZoellner
@CZoellner I need simple solution, from excel import start and finish date (start: 08:00:00, finish: 16:00:00) after import over odoo in field total I need result finish - start (08:00). I don't need how set field datetime or float or string and than convert to time. Any solution? Also is it possible after import start and finish automaticly populate field total if start and finish not empty?Pointer
What about defining the new field in Odoo and then get the correct results in the excel file already?CZoellner
@CZoellner Please see what I want postimg.org/image/o8no7if07Pointer
Yes, i already got it. But my point with doing the math already in excel stands! If you don't need onchange/compute behaviour in Odoo, that should be enough.CZoellner

2 Answers

2
votes

It should be like that,

total = fields.Float(string='Total', compute=_set_total)

@api.multi
def _set_total(self):
    for rec in self:
        rec.total = float(rec.finish or 0.0) - float(rec.start or 0.0)

However you can also create that field normal not functional

total = fields.Float(string='Total')

@api.onchange('finish','start')
def _set_total(self):
    self.total = float(self.finish or 0.00) - float(self.start or 0.00)
0
votes
def total_sum(self, cr, uid, ids, start, finish, context=None):
    res = {}
    res['total'] = finish - start
    return {'value': res}