我想要从excel导入数据到自定义模块。 我在excel中有开始和结束(datetime)是否可以在导入数据后定义字段总数(完成 - 开始)以获得结果?
例如:
class time(models.Model):
_name = "time"
_description = "Time"
start = fields.Datetime(string = 'Start', placeholder="Start")
finish = fields.Datetime(string='Finish', placeholder="Finish")
total = fields.Float(string='Total minutes', placeholder="Total")
_defaults = {
'total': (finish - start)
}
答案 0 :(得分:0)
您必须添加start
和finish
的onchange方法来计算total
。
实施例
@api.onchange('start', 'finish')
def onchange_start_finish(self):
for time in self:
time.total = time.finish - time.start
其他方式,
如果您将计算字段视为total.like,
total = fields.Float(compute='_methods_total', string='Total minutes', placeholder="Total")
@api.depends('start', 'finish')
def _methods_total(self):
for time in self:
time.total = time.finish - time.start