包含openerp的sql请求的Python函数
我有一个字段是函数的结果(包含openerp的sql请求的Python函数,python,openerp-7,Python,Openerp 7,我有一个字段是函数的结果(fields.function)。但是我的函数包含一个SQL请求,我不知道如何创建它 以下是我尝试过的: 功能: def _total_get(self, cr, uid, context=None): cr.execute('select total from hr_payslip_line where code = "22001"') return cr.fetchall() 'a':fields.function(_total_get
fields.function
)。但是我的函数包含一个SQL请求,我不知道如何创建它
以下是我尝试过的:
功能:
def _total_get(self, cr, uid, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
'a':fields.function(_total_get, type = 'float',store=False,method=True,obj="HrPayslip",string="L"),
def _total_get(self, cr, uid, ids, name, args, context=None):
function(fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float',fnct_search=None, obj=None, store=False, multi=False,...)
def _total_get(self, cr, uid, ids, name, args, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
total = cr.fetchone();
total = total and total[0] or 0.0
return dict.fromkeys(ids, total)
字段:
def _total_get(self, cr, uid, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
'a':fields.function(_total_get, type = 'float',store=False,method=True,obj="HrPayslip",string="L"),
def _total_get(self, cr, uid, ids, name, args, context=None):
function(fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float',fnct_search=None, obj=None, store=False, multi=False,...)
def _total_get(self, cr, uid, ids, name, args, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
total = cr.fetchone();
total = total and total[0] or 0.0
return dict.fromkeys(ids, total)
错误:
TypeError:_total_get()最多接受4个参数(给定7个)请尝试以下操作
def _total_get(self, cr, uid, ids, field_names=None, arg=False, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
函数默认采用7个参数。函数字段的签名为:
def _total_get(self, cr, uid, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
'a':fields.function(_total_get, type = 'float',store=False,method=True,obj="HrPayslip",string="L"),
def _total_get(self, cr, uid, ids, name, args, context=None):
function(fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float',fnct_search=None, obj=None, store=False, multi=False,...)
def _total_get(self, cr, uid, ids, name, args, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
total = cr.fetchone();
total = total and total[0] or 0.0
return dict.fromkeys(ids, total)
可用参数:
def _total_get(self, cr, uid, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
'a':fields.function(_total_get, type = 'float',store=False,method=True,obj="HrPayslip",string="L"),
def _total_get(self, cr, uid, ids, name, args, context=None):
function(fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float',fnct_search=None, obj=None, store=False, multi=False,...)
def _total_get(self, cr, uid, ids, name, args, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
total = cr.fetchone();
total = total and total[0] or 0.0
return dict.fromkeys(ids, total)
您的功能:
def _total_get(self, cr, uid, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
return cr.fetchall()
'a':fields.function(_total_get, type = 'float',store=False,method=True,obj="HrPayslip",string="L"),
def _total_get(self, cr, uid, ids, name, args, context=None):
function(fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float',fnct_search=None, obj=None, store=False, multi=False,...)
def _total_get(self, cr, uid, ids, name, args, context=None):
cr.execute('select total from hr_payslip_line where code = "22001"')
total = cr.fetchone();
total = total and total[0] or 0.0
return dict.fromkeys(ids, total)
注意:函数字段返回类型为dictionary