openerp change fields in a record by wizard
Question: I have installed openeducat module. In there I was trying to update timetable
record with update status to postponed which I created and Start-End Days by
wizard view.. & here is my python code in wizard. (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
    

And here is my 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>
    

and this is the normal timetable form view with my status bar.

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

and this is the error I have got.

    
    
    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
    


Answer: As the stack trace says, your error is caused by this line:

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

The problem is that your class is called 'op_timetable_postponed', not
'op_timetable'. If you change that line to the below then that should sort you
out :)

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

NOTE: If you want to directly create records of a specific type, the best way
might be to do something like the below:

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

