如何在openERP 7中添加一个函数? [英] How add a function in openERP 7?

查看:166
本文介绍了如何在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




这是我的代码:

<$ 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()

我的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,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

或者像这样: p>

  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

问候,


I was trying create a new module in openERP version 7. In my class I have this code :

_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"),
}

I don't find any solution to add a function in my class. The function which I need it return the sum of hour_from and hour_to. Can anyone help?

I try this code before declaring my _columns :

def _total(self, cr, uid, ids, name, args, context=None):

  res = {}

    res['totalhour'] = hour_from + hour_to

return res

When I restart the server I receive this error:

No handler found.

(Update from other post)

Well this is my code:

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()

My xml :

 <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>

When I want to add or edit a line, I have this error:

File "C:\Program Files\OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\orm.py", line 3729, in _read_flat
KeyError: 53

can you help mee pleese


wel this is my code:

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()

My xml :

 <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>

when i want to add or redit a line i have this error:

File "C:\Program Files\OpenERP 7.0-20130205-000102\Server\server\.\openerp\osv\orm.py", line 3729, in _read_flat
KeyError: 53

解决方案

Can you define you function like this and check again:

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

or like this:

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

Regards,

这篇关于如何在openERP 7中添加一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆