Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4291 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 10 25
27829
4
thg 6 21
40507
1
thg 12 20
3271
1
thg 4 18
8551
3
thg 9 15
10230