这是我的课程和方法。 我刚刚写了获取记录并需要打印它们。但是当在调试模式下运行openerp时,它没有工作。也不是那种方法。&还需要澄清OpenERP 7的提取方法
class namelistupdate(osv.osv):
def _mytest_query(self, cr, uid, ids, name, args, context=None):
print ('here is demo sql query function result ')
cr.execute("""SELECT module,(id*5000)as result FROM ir_model_data WHERE id=1""")
res = cr.dictfetchall()
print ('here is demo sql query function result ')
print (res)
def _invoiced_rate(self, cr, uid, ids, name, args, context):
self._mytest_query(self, cr, uid, ids, name, args, context)
amount_untaxed = 1
record_id = ids[0]
res = {record_id: 0.0}
if amount_untaxed == 0:
res[record_id] = 100.0
else:
res[record_id] = 50.0
return res
_name = "checkroll.namelist.update"
_description = "This table is for keeping Name list updates"
_columns = {
'date': fields.date("Date"),
'val': fields.function(_invoiced_rate, method=True, type='float', string='Test', store=True),
}
namelistupdate()
错误低于
Client Traceback (most recent call last): File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/http.py", line 203, in dispatch response["result"] = method(self, **self.params) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/controllers/main.py", line 1074, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/controllers/main.py", line 1066, in _call_kw return getattr(req.session.model(model), method)(*args, **kwargs) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/session.py", line 43, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/session.py", line 31, in proxy_method result = self.session.send(self.service_name, method, *args) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/session.py", line 104, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info) Server Traceback (most recent call last): File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/web/session.py", line 90, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/netsvc.py", line 293, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/service/web_services.py", line 618, in dispatch res = fn(db, uid, *params) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 131, in wrapper return f(self, dbname, *args, **kwargs) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4479, in create self.pool.get(object)._store_set_values(cr, user, ids, fields2, context) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4627, in _store_set_values result = self._columns[f].get(cr, self, ids, f, SUPERUSER_ID, context=context) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/fields.py", line 1131, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/checkroll/checkroll.py", line 55, in _invoiced_rate self._mytest_query(self, cr, uid, ids, name, args, context) TypeError: _mytest_query() takes exactly 7 arguments (8 given)
答案 0 :(得分:2)
在参数列表中删除> self 关键字。
答案 1 :(得分:1)
您在代码中为从函数调用函数所做的是完全错误的?
在python中调用一个函数,我们用圆括号指定函数名,你没有指定。
其次需要将参数作为函数中的参数数传递。
所以你的代码必须是这样的:
def _invoiced_rate(self, cr, uid, ids, name, args, context):
self._mytest_query(cr, uid, ids, name, args, context)
amount_untaxed = 1
record_id = ids[0]
res = {record_id: 0.0}
if amount_untaxed == 0:
res[record_id] = 100.0
else:
res[record_id] = 50.0
return res
完成函数后需要返回语句,否则返回None为默认值。
您可以参考如何在python中定义函数:http://docs.python.org/2/tutorial/controlflow.html#defining-functions
对于openerp功能,您可以在此处获得详细说明:http://doc.openerp.com/v6.1/developer/03_modules_2.html在“功能字段”标签下。 希望这个帮助