总和Odoo 9 [英] Sum times odoo 9

查看:112
本文介绍了总和Odoo 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在树状视图中使用计算时,总和不可见.当使用onChange sum可见时,任何解决方案都如何解决.从.csv插入数据后,我需要自动填充time_total字段进行计算.

When use compute in tree view sum is not visible. When use onChange sum is visible any solution how fix it. I need compute after insert data from .csv automaticly populate time_total fields.

示例:

来源:

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)  

在表单视图中手动更改值时,树视图中的显示总和

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

推荐答案

只需对此做一个更改,

将该字段存储在数据库中,它将显示该字段的总和.

Store that field in database and it will show you the sum of that field.

total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time', store=True)

然后删除onchange和insted使用取决于

And then remove onchange and insted use depends

@api.depends('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)

这种情况背后的原因是,需要按操作分组 数据库中的字段,因为oooo框架为分组依据准备了查询 然后从数据库中获取结果.因此,如果该字段不存在 在数据库中,然后如何显示结果.

There is reason behind that scenario is, group by operation required field in database because odoo frameworks prepared query for group by and then get result back from the database. So if the field is not there in database then how it can show you result.

这篇关于总和Odoo 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆