0
votes

Hello to all I have been developing module under Odoo 8. I have a class "hrEmployee" with "_inherit=hr.employee" , now in my hrEmployee there is a One2many field having relation with another model "hr.employee.visa". I want to get the field values of the "hrEmployee" with onchange function defined on the field of "hr.employee.visa". Like when I change field value of "hrEmployee", I can get the field value entered on the current form (hrEmployee). How am I able to achieve this in Odoo v8? My Python code is shown below:

class hrEmployee(models.Model):

    _inherit = "hr.employee"               
    diwan_no = fields.Char('Diwan No', size=30, help='Diwan Number')   
    zeo_number = fields.Char('ZEO Number',size=30, help='ZEO Number')    
    visas_ids = fields.One2many('hr.employee.visas', 'employee_id', 'Visas')                    

class hr_employee_visas(models.Model):       

    _name='hr.employee.visas'
    employee_id = fields.Many2one("hr.employee.visas", "Employee" )

    @api.onchange('visas_number')    
    @api.depends( 'visas_number')    
    def _visa_num(self):    
        cr=self._cr    
        uid=self._uid    
        ids=self._ids
        for id in ids:
            obj1=self.pool.get('hr.employee').browse(cr,uid,id,context=None)  
            print obj1.name_related          

    visas_sponsor = fields.Char('Sponsor')    
    visas_states = fields.Selection([('apply','Apply'),('active','Active'),('expire','Expire'),('cancel','Cancelled')], string='State' )    
    visas_number = fields.Char('Visa No', help='Visa Number')   

I tried to use self.pool.get browse but it gives me "False" . Plz guide me or point me my mistake. Hopes for suggestion

1
It's not clear what you want to achieve. The onchange is client-side action, triggered when edit the visas_number field in the form for hr.employee.visas. What do you expect to be done when that happens?Daniel Reis
Look the main form is the hrEmployee (that inherits 'hr.employee' ). There is inherited field 'name_related' .A One2many field is used here which is related with the 'hr.employee.visas'. Now the onchange function defined on the child form (model='hr.employee.visas') should print me the value that i entered on the parent form (model='hrEmployee')Arsalan Sherwani
There is no name_related in your code. You want the employee name to be displayed on the visa form? It should be by default. Sorry, I'm still confused.Daniel Reis
'name_related' is being inherited through hr.employeeArsalan Sherwani

1 Answers

0
votes

Try following,

class hr_employee_visas(models.Model):       

    _name='hr.employee.visas'
    employee_id = fields.Many2one("hr.employee", "Employee" )

    @api.onchange('visas_number')    
    @api.depends( 'visas_number')    
    def _visa_num(self):    
        for obj in self:
            print obj.employee_id.name  

Here is the mistake

employee_id = fields.Many2one("hr.employee.visas", "Employee" )

You need to set hr.employee here.

No need to write both of the decorators together, in case of any changes into the visas_number field this method will be called, you can use any of the single decorator for this.