Python 如何在openERP 7中添加函数?
我试图在openERP版本7中创建一个新模块。在我的课堂上,我有以下代码:Python 如何在openERP 7中添加函数?,python,function,field,openerp,Python,Function,Field,Openerp,我试图在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
_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\u和hour\u之和。有人能帮忙吗
在声明我的_列之前,我尝试以下代码:
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()
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()
我的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>
<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>
你能帮我吗
这是我的代码:
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()
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()
我的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>
<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>
您可以这样定义您的函数:
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
这里是如何定义函数字段的链接,希望对您有所帮助
您可以这样定义您的功能并再次检查:
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] = 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
尊敬的,请您共享完整的异常堆栈好吗?这会让你对错误有更多的了解。谢谢你的回答。这是halp mee并解决了部分问题,但当我更新我的应用程序时,我是一个新的错误,我去查看我有此错误关键错误9
非常感谢您非常非常匹配它的工作与第一个功能thak you Againts感谢您保存我的a**