This question has been flagged
2 Replies
3130 Views

I have a relation between the fuel and voucher classes with the field 'amount_used' that calculates the number of voucher x used in fuel without problems 

_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
}

when I add the store parameter in 'amount_used' I have an update problem

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

Avatar
Discard
Author Best Answer

The solution :


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

Avatar
Discard
Best Answer

Hi mehdi,

here you have function field in 'fleet.voucher' object and in its store parameter you are using the field(voucher_id) of 'fleet.voucher.log.fuel' object, so you should return the ids of 'fleet.voucher' object only(currently you are getting the ids of 'fleet.vehicle.log.fuel' object thats why u are getting the error.

use:

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

Regards

Avatar
Discard