Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

wizard for update field in objects

By
Ait-Mlouk Addi
on 11/13/13, 7:28 AM 1,011 views

HI every one i tray to update level and classroom for students with this function using wizard after testing i get this error :

File "/home/dbm/workspace_2/OpenERP_v7/openerp/osv/orm.py", line 488, in __getattr__ raise AttributeError(e) AttributeError: 'Field student not found in browse_record(madrassa.registration, 21)'

this is my classe and function

class madrassa_registration_megration(osv.osv_memory):

_name='madrassa.registration.megration'

def _get_year(self,cr,uid,context={}):
    return self.pool.get('madrassa.academic.year').get_active_year(cr,uid)


_columns = {

        'year' : fields.many2one('madrassa.academic.year',u'Année académic',required=True),

        'student' : fields.many2one('madrassa.student',u'Elève',required=True),

        'internal_code' : fields.char(u'Code interne',size=50,readonly=True),

        'academic_code' : fields.char(u'Code académique',size=50),

        'cycle' : fields.related('student','cycle',string = u'Cycle précédente',type='many2one',relation='madrassa.academic.cycle',readonly=True),

        'level' : fields.related('student','level',string = u'Niveau précédente',type='many2one',relation='madrassa.academic.level',readonly=True),

        'classroom' : fields.related('student','classroom',string = u'Classe précédente',type='many2one',relation='madrassa.academic.classroom',readonly=True),

        'section' : fields.related('student','section',string = u'Section précédente',type='many2one',relation='madrassa.academic.section',readonly=True),




        'new_level' : fields.many2one('madrassa.academic.level',u'Nouveau Niveau',required=True),

        'new_classroom' : fields.many2one('madrassa.academic.classroom',u'Nouvelle classe'),



        'new_section' : fields.related('new_level','section',string = u'Nouvelle section',type='many2one',relation='madrassa.academic.section'),

        'new_cycle' : fields.related('new_section','cycle',string = u'Nouveau cycle',type='many2one',relation='madrassa.academic.cycle'),

                }

_defaults = {  
    'year' : _get_year,

    }

def onchange_student(self,cr,uid,ids,student,year,context={}):
    data={}
    ids_registration=self.pool.get('madrassa.registration').search(cr,uid,[('student','=',student)])
    if ids_registration:
                ids_registration.sort(reverse=True)
                object_registration=self.pool.get('madrassa.registration').browse(cr,uid,ids_registration[0])
                if object_registration:
                    data['cycle'] = object_registration.cycle and object_registration.cycle.id or False
                    data['section'] = object_registration.section and object_registration.section.id or False
                    data['level'] = object_registration.level and object_registration.level.id or False
                    data['classroom'] = object_registration.classroom and object_registration.classroom.id or False
                    data['internal_code'] = object_registration.student and object_registration.student and object_registration.student.internal_code or False

    return {'value' : data}

def view_init(self, cr, uid, fields_list, context=None):
    """
     Creates view dynamically and adding fields at runtime.
     @param self: The object pointer.
     @param cr: A database cursor
     @param uid: ID of the user currently logged in
     @param context: A standard dictionary
     @return: New arch of view with new columns.
    """
    if context is None:
        context = {}
    year_id=self.pool.get('madrassa.academic.year').get_active_year(cr,uid)
    if not year_id:
        raise osv.except_osv(u'Inscription impossible!',u'Assurez-vous qu\'une année académique soit en cours.')
    res = super(madrassa_registration_megration, self).view_init(cr, uid, fields_list, context=context)
    return res

def action_megration(self,cr,uid,ids,context={}):
    if ids:
        year_id=self.pool.get('madrassa.academic.year').get_active_year(cr,uid)
        if not year_id:
            raise osv.except_osv(u'Réinscription impossible!',u'Assurez-vous qu\'une année académique soit en cours.')
        else:

            object_megration=self.browse(cr,uid,ids[0])
            if object_megration:    

                data_register={
                                'student' : object_megration.student and object_megration.student.id or False,
                                'year' : object_megration.year and object_megration.year.id or False,
                                'level' : object_megration.new_level and object_megration.new_level.id or False,
                                'classroom' : object_megration.new_classroom and object_megration.new_classroom.id or False,
                                'academic_code' : object_megration.academic_code or False,
                                    }
                self.pool.get('madrassa.registration').write(cr,uid,ids,data_register)
    return {'type': 'ir.actions.act_window_close'}

def onchange_level(self,cr,uid,ids,level,context={}):
    data={}
    if level:
        object_level=self.pool.get('madrassa.academic.level').browse(cr,uid,level)
        if object_level:
            data['new_section'] = object_level.section and object_level.section.id or False
            data['new_cycle'] = object_level.section and object_level.section and object_level.section.cycle and object_level.section.cycle.id or False
    return {'value' : data }

madrassa_registration_megration()

i change the old level and old classroom and after i want to enter new level and classroom thanks

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 11/13/13, 7:28 AM
Seen: 1011 times
Last updated: 3/16/15, 8:10 AM