openerp通过向导更改记录中的字段

时间:2015-01-01 09:54:52

标签: python openerp openerp-7

我已经安装了openeducat模块。在那里,我试图更新时间表记录,更新状态为推迟我创建的和开始结束日期的向导视图。&这是我向导中的python代码。 (postponed_op_timetable.py)

from osv import osv, fields


class op_timetable_postponed(osv.osv_memory):
    _name = 'op.timetable.postponed'
    _inherit = 'op.timetable'
    _columns = {

}


def action_postponed_timetable(self, cr, uid, vals, context=None):
    res = {}
    timetable_id = super(op_timetable, self).create(cr, uid, vals, context=context)
    for this_obj in self.browse(cr, uid, timetable_id[0], context=context):
        self.write(cr, uid, timetable_id, {
            'start_datetime': this_obj.start_datetime,
            'end_datetime': this_obj.end_datetime,
            'state': 'postponed'
        }, context=context)
    return res

这是我的xml(postponed_op_timetable_view.xml)

<?xml version="1.0" encoding="UTF-8"?>
    <openerp>
        <data>
            <record id="view_op_timetable_postponed" model="ir.ui.view">
                <field name="name">op.timetable.postponed.form</field>
                <field name="model">op.timetable.postponed</field>
                <field name="arch" type="xml">
                    <form string="Postponed Timetable" col="4" version="7.0">
                        <group colspan="2">
                            <field name="start_datetime" colspan="2"/>
                            <field name="end_datetime" colspan="2"/>
                        </group>
                        <footer>
                            <button type="special"
                                    special="cancel"
                                    string="Cancel"
                                    icon="gtk-cancel"/>

                        <button type="object"
                                name="action_postponed_timetable"
                                string="Postponed"
                                icon="gtk-ok"/>
                     </footer>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_op_timetable_postponed">
            <field name="name">Postponed Timetable</field>
            <field name="type">ir.actions.act_window</field>
            <field name="src_model">op.timetable</field>
            <field name="res_model">op.timetable.postponed</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_op_timetable_postponed"/>
            <field name="context">{'default_timetable_id': active_id}</field>
            <field name="target">new</field>
        </record>
    </data>
</openerp>

这是我的状态栏的正常时间表表单视图。

    <record id="view_op_timetable_form" model="ir.ui.view">
        <field name="name">op.timetable.form</field>
        <field name="model">op.timetable</field>
        <field name="priority" eval="8" />
        <field name="arch" type="xml">
            <form string="Time Table" version="7.0">
                <header>
                    <button name="action_complete" string="Complete" type="workflow" icon="gtk-apply" states="planned,postponed"/>
                    <button name="%(action_op_timetable_postponed)d" string="Postponed" type="action"
                            icon="gtk-jump-to" states="planned" context="{'timetable_id': active_id}"/>
                    <button name="action_cancel" string="Cancel" type="workflow" icon="gtk-cancel" states="planned,postponed"/>
                    <field name="state" widget="statusbar" readonly="True"          statusbar_colors='{"r":"red"}'
                            statusbar_visible="planned,postponed,completed,cancelled"/>
                </header>
                <sheet>
                    <separator colspan="4" string="Time Table" />
                    <group colspan="4" col="4">
                        <field name="faculty_id" />
                        <field name="standard_id" />
                        <field name="division_id" />
                        <field name="period_id" />
                        <field name="subject_id" />
                        <field name="classroom_id" />
                        <field name="start_datetime" />
                        <field name="end_datetime" />
                        <field name="type"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

这是我遇到的错误。

Client Traceback (most recent call last):
  File     "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\http.py",     line 204, in dispatch
    response["result"] = method(self, **self.params)
  File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\controllers\main.py", line 1132, in call_button
    action = self._call_kw(req, model, method, args, {})
  File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\controllers\main.py", line 1120, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\session.py", line 42, in proxy
    result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
  File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\session.py", line 30, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\session.py", line 103, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)


Server Traceback (most recent call last):
      File "E:\Development\MySchool_latest\Source\trunk\openerp.myschool\server\openerp\addons\web\session.py", line 89, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\service\web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\osv\osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\osv\osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\osv\osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\server\openerp\osv\osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "E:\Development\MySchool_New\Source\trunk\openerp.myschool\src\myschool\wizard\postponed_op_timetable      .py", line 13, in action_postponed_timetable
    timetable_id = super(op_timetable, self).create(cr, uid, vals, context=context)
    NameError: global name 'op_timetable' is not defined

1 个答案:

答案 0 :(得分:0)

正如堆栈跟踪所示,您的错误是由此行引起的:

timetable_id = super(op_timetable, self).create(cr, uid, vals, context=context)

问题是你的类被称为'op_timetable_postponed',而不是'op_timetable'。如果您将该行更改为以下,则应该将您排除在外:)

timetable_id = super(op_timetable_postponed, self).create(cr, uid, vals, context=context)

注意:如果您想直接创建特定类型的记录,最好的方法可能是执行以下操作:

tt_obj = self.pool.get('op.timetable')
timetable_id = tt_obj.create(cr, uid, vals, context)