将参数存储在函数中

时间:2015-05-26 12:11:59

标签: openerp odoo

我在燃料和凭证类别与字段' amount_used'之间存在关系。计算燃料中使用的凭证x的数量没有问题

_name = 'fleet.vehicle.log.fuel'
'voucher_id': fields.many2one('fleet.voucher', 'Voucher'),

_name = 'fleet.voucher'
'amount_used': fields.function(_count_all, type='integer', string="Amount Used")

def _count_all(self, cr, uid, ids, field_name, arg, context=None):

    Fuel = self.pool['fleet.vehicle.log.fuel']
    return {
        voucher_id: Fuel.search_count(cr, uid, [('voucher_id', '=', voucher_id)], context=context)
for voucher_id in ids
    }

当我在' amount_used'中添加商店参数时我有更新问题

store=True or store={'fleet.vehicle.log.fuel': (lambda self, cr, uid, ids, c={}: ids, ['voucher_id'], 10)}

1 个答案:

答案 0 :(得分:0)

store={'fleet.vehicle.log.fuel': (_get_voucher, ['voucher_id'], 10)}



def _get_voucher(self, cr, uid, ids, context=None):

res = []

for fuel in self.pool.get('fleet.vehicle.log.fuel').browse(cr, uid, ids, context=context):

if fuel.voucher_id:

res.append(fuel.voucher_id.id)

return res