Odoo Help


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.


calculated field with new API attribute calculate

Yves Goldberg
on 6/3/16, 2:41 AM 352 views

in my model.py, I have:

totFee = fields.Float(compute='_compute_totFee')

def _compute_totFee(self): 
for rec in self: 
self.totFee = 44

I get an error message:

ERROR crc openerp.http: Exception during JSON request handling.

Traceback (most recent call last):

File "/opt/odoo/openerp/http.py", line 643, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/opt/odoo/openerp/http.py", line 680, in dispatch

result = self._call_function(**self.params)

File "/opt/odoo/openerp/http.py", line 316, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/opt/odoo/openerp/service/model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "/opt/odoo/openerp/http.py", line 309, in checked_call

result = self.endpoint(*a, **kw)

File "/opt/odoo/openerp/http.py", line 959, in __call__

return self.method(*args, **kw)

File "/opt/odoo/openerp/http.py", line 509, in response_wrap

response = f(*args, **kw)

File "/opt/enterprise-9/web/controllers/main.py", line 911, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/opt/enterprise-9/web/controllers/main.py", line 903, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "/opt/odoo/openerp/api.py", line 250, in wrapper

return old_api(self, *args, **kwargs)

File "/opt/odoo/openerp/models.py", line 3193, in read

result = BaseModel.read(records, fields, load=load)

File "/opt/odoo/openerp/api.py", line 248, in wrapper

return new_api(self, *args, **kwargs)

File "/opt/odoo/openerp/models.py", line 3239, in read

values[name] = field.convert_to_read(record[name], use_name_get)

File "/opt/odoo/openerp/models.py", line 5740, in __getitem__

return self._fields[key].__get__(self, type(self))

File "/opt/odoo/openerp/fields.py", line 829, in __get__


File "/opt/odoo/openerp/fields.py", line 936, in determine_value


File "/opt/odoo/openerp/fields.py", line 891, in compute_value


File "/opt/odoo/openerp/fields.py", line 881, in _compute_value

getattr(records, self.compute)()

AttributeError: 'transactions' object has no attribute '_compute_totFee'

how would I write that function?


Hi Yves, Is your function above the fields.Float that has the compute field? If the function is under the fields.Float move it above the fields.Float. Regards, Yenthe

on 6/3/16, 3:14 AM

check the indentation of method, it should be inside the class

Prakash Sharma
on 6/3/16, 5:18 AM
On 6/7/16, 7:16 AM

use compute field

Yves Goldberg
On 6/3/16, 5:25 AM

thank you a bunch Yenthe, Prakash and Nicolas!!

It works now :)

Nicolas JEUDY
On 6/3/16, 3:59 AM


- without the complete file it is difficult to help you.

on note:

@api.depends('field1','field2')def _compute_totFee(self):      
for rec in self: 
self.totFee = 44

should be:

@api.depends('field1','field2')def _compute_totFee(self):      
for rec in self:
rec.totFee = 44

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)


Asked: 6/3/16, 2:41 AM
Seen: 352 times
Last updated: 6/7/16, 7:16 AM