请更正代码,因为此时我遇到属性错误
XML如下:
<field name="rate" on_change="on_change_ded_cal(rate)"/>
<field name="ded"/>
.Py文件在下面给出
def on_change_ded_cal(self, cr, uid, ids, rate, context=None):
x=rate+2
return {'value': {'ded': x}}
完整的错误消息在下面给出
OpenERP Server Error
Client Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20131006- 231029\Server\server\openerp\addons\web\http.py", line 204, in dispatch
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\controllers\main.py", line 1128, in call_kw
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\controllers\main.py", line 1120, in _call_kw
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 42, in proxy
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 30, in proxy_method
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 103, in send
Server Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 89, in send
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\osv.py", line 197, in execute
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
**AttributeError: 'test_base' object has no attribute 'on_change_ded_cal'**
下面还提供了完整的.py文件供进一步参考
from osv import osv
from osv import fields
class test_base(osv.osv):
_name='test.base'
_columns={
'name':fields.char('Name'),
'email':fields.char('Email'),
'code':fields.integer('Unique ID'),
'sal':fields.float('Salary'),
'rate':fields.selection((('10','10%'), ('20','20%'),('30','30%')),
'Percentage of Deduction'),
'ded':fields.float('Deduction'),
}
test_base()
def on_change_ded_cal(self, cr, uid, ids, rate, context=None):
x=rate+2
return {'value': {'ded': x}}
答案 0 :(得分:0)
试试这个,
from osv import osv
from osv import fields
class test_base(osv.osv):
_name='test.base'
_columns={
'name':fields.char('Name'),
'email':fields.char('Email'),
'code':fields.integer('Unique ID'),
'sal':fields.float('Salary'),
'rate':fields.selection((('10','10%'), ('20','20%'),('30','30%')),
'Percentage of Deduction'),
'ded':fields.float('Deduction'),
}
def on_change_ded_cal(self, cr, uid, ids, rate, context=None):
x=rate+2
return {'value': {'ded': x}}
test_base()