Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
7836 Vizualizări

in my model.py, I have:

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


@api.depends('field1','field2')
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__

self.determine_value(record)

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

self.compute_value(recs)

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

self._compute_value(records)

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?

TIA



Imagine profil
Abandonează

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

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

Cel mai bun răspuns

use compute field

Imagine profil
Abandonează
Autor Cel mai bun răspuns

thank you a bunch Yenthe, Prakash and Nicolas!!

It works now :)

Imagine profil
Abandonează
Cel mai bun răspuns

Hello, 

- 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


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
aug. 25
351
2
iul. 25
2803
3
iul. 25
618
1
iun. 25
2068
1
aug. 25
987