콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
7854 화면

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



아바타
취소

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

베스트 답변

use compute field

아바타
취소
작성자 베스트 답변

thank you a bunch Yenthe, Prakash and Nicolas!!

It works now :)

아바타
취소
베스트 답변

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


아바타
취소
관련 게시물 답글 화면 활동
1
8월 25
388
2
7월 25
2831
3
7월 25
637
1
6월 25
2105
1
8월 25
1015