我已经使用了这段代码及其工作
def name_get(self, cr, uid, ids, kecamatan_id,city_id):
print"--------------------------",kecamatan_id
if kecamatan_id:
city= self.pool.get("wtc.kecamatan").browse(cr, uid, kecamatan_id)
return {'value' {'city_id':city.city_id.id,'province_id':city.province_id.id}}
in my .xml
<field name="kecamatan_id" on_change="name_get(kecamatan_id, city_id)"/>
但是当我点击保存按钮版本错误但数据已成功保存
Traceback (most recent call last): File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 499, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 516, in dispatch result = self._call_function(**self.params) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 282, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 279, in checked_call return self.endpoint(*a, **kw) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 732, in __call__ return self.method(*args, **kw) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 375, in response_wrap response = f(*args, **kw) File "/home/susi/odoo/addons/HONDA/web/controllers/main.py", line 944, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/susi/odoo/addons/HONDA/web/controllers/main.py", line 925, in _call_kw names = dict(request.session.model(model).name_search('', args[0], **kwargs)) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 834, in proxy result = meth(cr, request.uid, *args, **kw) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 332, in old_api result = method(recs, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/models.py", line 1760, in name_search return self._name_search(name, args, operator, limit=limit) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 235, in wrapper return new_api(self, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 464, in new_api result = method(self._model, cr, uid, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/models.py", line 1773, in _name_search res = self.name_get(cr, access_rights_uid, ids, context) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs)
TypeError: name_get() takes exactly 6 arguments (5 given)
我应该如何修复我的代码?
答案 0 :(得分:0)
除self
外,该方法接受5个参数,但代码传递4个参数。
self.name_get(cr, access_rights_uid, ids, context)
^^^^^^^
根据方法签名,代码正在传递context
而不是kecamatan_id
和city_id
。
def name_get(self, cr, uid, ids, kecamatan_id, city_id):
^^^^^^^^^^^^^^^^^^^^^