I am on account_voucher model I want to change the amount field's type into functionnal field, so I did :
class AccountVoucher(orm.Model):
_inherit="account.voucher"
_name="account.voucher"def _total_payed(self, cr, uid, ids, amount, arg, context=None):
res = {}
voucher = self.browse(cr, uid, ids[0], context=context)
for line in voucher.line_cr_ids:
res[voucher.id] += line.amount
return res_columns = {
'amount': fields.function(_total_payed, method=True, string='Amount payed', type='float'),
}
The purpose is to change it to readonly=True, and make it compute the sum of all the amount payed for all the voucher lines displayed for the current selected customer.
Error Traceback :
File "/opt/openerp/server/openerp/osv/orm.py", line 3800, in _read_flat res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res) File "/opt/openerp/server/openerp/osv/fields.py", line 1145, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) File "/opt/openerp/server/openerp/addons/account_payment_bl/account_voucher.py", line 56, in _total_payed res[voucher.id] += line.amount KeyError: 5616
what's wrong with the key ?