Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Store parameter in a function

By
mehdi
on 5/26/15, 8:09 AM 503 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)}

1
mehdi
On 5/26/15, 8:09 PM

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

1

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 5/26/15, 2:01 PM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/26/15, 8:09 AM
Seen: 503 times
Last updated: 5/26/15, 8:15 PM