如何在openERP 7中添加一个函数? [英] How add a function in openERP 7?
问题描述
_columns = {
'hour_from':fields.float('Work from',required = True),
'hour_to':fields.float(Work to,required = True),
'totalhour ':fields.function(_total,method = True,string ='Total Attendance',multi =_ total),
}
我没有找到任何解决方案在我的课程中添加一个函数。我需要它的函数返回 hour_from
和 hour_to
的总和。任何人都可以帮忙吗?
在声明我的_columns之前,我尝试了这段代码:
def _total(self,cr,uid,id,name,args,context = None):
$ b res = {}
res ['totalhour'] = hour_from + hour_to
return res
当我重新启动服务器时,我收到此错误:
找不到处理程序。
(从其他帖子更新) $ b
这是我的代码:
def _total(self,cr,uid,ids,name, args,context = None):
res = {}
记录在self.browse(cr,uid,ids,context = context)中:
res ['totalhour'] =记录。 hour_from + record.hour_to
return res
$ b $ class hr_analytic_timesheet(osv.osv):
_name =hr.analytic.timesheet
_inherit =hr.analytic .timesheet
_columns = {
'hour_from':fields.float('Work from',required = True,help =开始和结束工作时间。 ,select = True),
'hour_to':fields.float(Work to,required = True),
$ b'b'totalhour':fields.function(_total,type ='float ',method = True,string ='Total Hour'),
}
hr_analytic_timesheet()
My xml:
< record id =view_ov_perf_timesheet_line_treemodel =ir.ui .view> ;
< field name =name> hr.analytic.timesheet.tree< / field>
< field name =model> hr.analytic.timesheet< / field>
< field name =inherit_idref =hr_timesheet.hr_timesheet_line_tree/>
< field name =archtype =xml>
< field name =unit_amountposition =replace>
< field name =hour_fromwidget =float_timestring =Heuredébut/>
< field name =hour_towidget =float_timestring =Heure fin/>
< field name =totalhourwidget =float_time/>
< / field>
< / field>
< / record>
当我想添加或编辑一行时,我有这个错误:
文件C:\ Program Files \OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\\ \\orm.py,第3729行,在_read_flat中
KeyError:53
你能帮忙吗mee pleese
这是我的代码: 我的xml: 当我想添加或者重做一行时,我有这个错误: 或者像这样: p> 问候, I was trying create a new module in openERP version 7. In my class I have this code : I don't find any solution to add a function in my class. The function which I need it return the sum of I try this code before declaring my _columns : When I restart the server I receive this error: (Update from other post) Well this is my code: My xml : When I want to add or edit a line, I have this error: can you help mee pleese wel this is my code: My xml : when i want to add or redit a line i have this error:
Can you define you function like this and check again: or like this: Regards, 这篇关于如何在openERP 7中添加一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ self.browse(cr,uid,uid,id,name,args,context = None):
res = {}
,ids,context = context):
res ['totalhour'] = record.hour_from + record.hour_to
return res
class hr_analytic_timesheet(osv.osv):
_name =hr.analytic.timesheet
_inherit =hr.analytic.timesheet
_columns = {
'hour_from':fields.float ('Work from',required = True,help =开始和结束工作时间,select = True),
'hour_to':fields.float(Work to,required = True),
'totalhour':fields.function(_total,type ='float',method = True,string ='Total Hour'),
}
hr_analytic_timesheet()
< record id =view_ov_perf_timesheet_line_treemodel =ir.ui.view>
< field name =name> hr.analytic.timesheet.tree< / field>
< field name =model> hr.analytic.timesheet< / field>
< field name =inherit_idref =hr_timesheet.hr_timesheet_line_tree/>
< field name =archtype =xml>
< field name =unit_amountposition =replace>
< field name =hour_fromwidget =float_timestring =Heuredébut/>
< field name =hour_towidget =float_timestring =Heure fin/>
< field name =totalhourwidget =float_time/>
< / field>
< / field>
< / record>
文件C:\ Program Files \ OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\ orm.py,line 3729,in _read_flat
KeyError:53
$ $ $ $ $ c $ def $ _total(self,cr,uid, ids,name,args,context = None):
res = {}
用于记录self.browse(cr,uid,ids,context = context):
res [record.id ] = record.hour_from + record.hour_to
return res
def _total(self,cr,uid,id,name,args,context = None):
res = {}
记录在self.browse(cr,uid,ids,context = context)中:
res [record.id] = {'totalhour':0.0}
res [record.id] ['totalhour'] = record.hour_from + record.hour_to
return res
_columns = {
'hour_from' : fields.float('Work from', required=True),
'hour_to' : fields.float("Work to", required=True),
'totalhour': fields.function(_total, method=True, string='Total Attendance', multi="_total"),
}
hour_from
and hour_to
. Can anyone help?def _total(self, cr, uid, ids, name, args, context=None):
res = {}
res['totalhour'] = hour_from + hour_to
return res
No handler found.
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res['totalhour'] = record.hour_from + record.hour_to
return res
class hr_analytic_timesheet(osv.osv):
_name = "hr.analytic.timesheet"
_inherit = "hr.analytic.timesheet"
_columns = {
'hour_from' : fields.float('Work from', required=True, help="Start and End time of working.", select=True),
'hour_to' : fields.float("Work to", required=True),
'totalhour' : fields.function(_total, type='float', method=True, string='Total Hour'),
}
hr_analytic_timesheet()
<record id="view_ov_perf_timesheet_line_tree" model="ir.ui.view">
<field name="name">hr.analytic.timesheet.tree</field>
<field name="model">hr.analytic.timesheet</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="arch" type="xml">
<field name="unit_amount" position="replace">
<field name="hour_from" widget="float_time" string="Heure début"/>
<field name="hour_to" widget="float_time" string="Heure fin" />
<field name="totalhour" widget="float_time"/>
</field>
</field>
</record>
File "C:\Program Files\OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\orm.py", line 3729, in _read_flat
KeyError: 53
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res['totalhour'] = record.hour_from + record.hour_to
return res
class hr_analytic_timesheet(osv.osv):
_name = "hr.analytic.timesheet"
_inherit = "hr.analytic.timesheet"
_columns = {
'hour_from' : fields.float('Work from', required=True, help="Start and End time of working.", select=True),
'hour_to' : fields.float("Work to", required=True),
'totalhour' : fields.function(_total, type='float', method=True, string='Total Hour'),
}
hr_analytic_timesheet()
<record id="view_ov_perf_timesheet_line_tree" model="ir.ui.view">
<field name="name">hr.analytic.timesheet.tree</field>
<field name="model">hr.analytic.timesheet</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="arch" type="xml">
<field name="unit_amount" position="replace">
<field name="hour_from" widget="float_time" string="Heure début"/>
<field name="hour_to" widget="float_time" string="Heure fin" />
<field name="totalhour" widget="float_time"/>
</field>
</field>
</record>
File "C:\Program Files\OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\orm.py", line 3729, in _read_flat
KeyError: 53
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = record.hour_from + record.hour_to
return res
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = {'totalhour' : 0.0}
res[record.id]['totalhour'] = record.hour_from + record.hour_to
return res