Python 过滤器后的field.function之和
我在班上创建了一个模块openERP我有3个列: 函数中的hour_from(type float)、hour_to(type float)和totalhour(fileds.function)计算hour_from和hour_to之间的差值Python 过滤器后的field.function之和,python,function,openerp,Python,Function,Openerp,我在班上创建了一个模块openERP我有3个列: 函数中的hour_from(type float)、hour_to(type float)和totalhour(fileds.function)计算hour_from和hour_to之间的差值 def _total(self, cr, uid, ids, name, args, context=None): res = {} for record in self.browse(cr, uid, ids, context=context):
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = record.hour_to - record.hour_from
return res
_columns = {
'hour_from' : fields.float('Work from', required=True, help="Start and End time of working.", select=True),
'hour_to' : fields.float("Work to", required=True),
'totalhour' : fields.function(_total, type='float', method=True, string='Total Hour'),
}
在xml文件中,我在树记录中有以下代码:
<field name="arch" type="xml">
<field name="hour_from" widget="float_time" string="Heure début"/>
<field name="hour_to" widget="float_time" string="Heure fin" />
<field name="totalhour" widget="float_time"/>
</field>
</field>
例如,当我尝试按用户筛选树结果时,它很好地解决了我的问题
我有hour_to的一些,hour_from的和,但不是totalhour的和。我想要的是不同的:我只想要totalhour的和
我希望我能解释我的问题。有人能帮我吗?尝试在totalhour字段中使用“总和”:
<field name="arch" type="xml">
<field name="hour_from" widget="float_time" string="Heure début"/>
<field name="hour_to" widget="float_time" string="Heure fin" />
<field name="totalhour" widget="float_time" sum="Total"/>
</field>
</field>
很好,谢谢,但这不是我想要的,我想我是用一个不好的词描述了这个问题。对不起,我的问题是当我按用户分组树结果时,我有用户(10)小时从(34小时)到(45)总小时()这是我的问题,我想要的是在对树结果进行分组后进入第一行,即总小时数的和,而不是其他小时数的和。也许您应该对totahour字段使用store属性?