3
在樹視圖中使用compute時,sum不可見。當使用onChange總和時,任何解決方案都是可見的。從.csv插入數據後,我需要計算自動填充time_total字段。總和時間odoo 9
例子:
來源:
class my_data(models.Model):
_name = "my.data"
_description = "My Data"
user = fields.Char(string = 'User')
date = fields.Date(string = 'Date')
start_time = fields.Datetime(string='Start', placeholder="Start", default="2016-01-01 00:00:00.624139")
finish_time = fields.Datetime(string='Finish', placeholder="Finish", default="2016-01-01 00:00:00.624139")
total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time')
#total_time = fields.Float(string='Total minutes', placeholder="Total minutes")
@api.multi
@api.onchange('start_time', 'finish_time')
def onchange_time(self):
for rec in self:
time1 = datetime.strptime(rec.start_time, "%Y-%m-%d %H:%M:%S")
time2 = datetime.strptime(rec.finish_time, "%Y-%m-%d %H:%M:%S")
rec.total_time = (time2 - time1).seconds/float(60*60)
SHOW SUM樹視圖時,在窗體視圖MANUAL變化值
@api.onchange('start_time', 'finish_time')
def onchange_time(self):
time1 = datetime.strptime(self.start_time, "%Y-%m-%d %H:%M:%S")
time2 = datetime.strptime(self.finish_time, "%Y-%m-%d %H:%M:%S")
self.total_time = (time2 - time1).seconds/float(60*60)
請在您的問題中包含您的代碼,輸出和預期輸出;不要鏈接到它。 – Evert
@Evert源代碼添加 – Pointer