0
votes

I have been developing module for Odoo8 under Ubuntu 14.04 . I am trying to set field data of my current class to field data of other class. I tried to assign the value but it does not get shown on the field of that other class. On printing the value on command prompt, it displays the right value but on Odoo field the textbox remains empty. Any clue or suggestions on this? Hopes for suggestion. Please check my code below

class hrEmployee(models.Model):

    _inherit = "hr.employee"



    passports_ids =  fields.One2many('hr.employee.passports', 'employee_id', 'Passport')          

class hr_employee_passports(models.Model):  
    _name='hr.employee.passports'    
    employee_id = fields.Many2one("hr.employee", "Employee" , ondelete="cascade")


    @api.onchange('passports_number')    
    @api.depends( 'passports_number')    
    def set_passport(self):
        result={} 

        if self.passports_number:

           for obj in self.employee_id:    
               obj.passport_id=self.passports_number
               print obj.passport_id  # this is the inherited field        

   passports_number = fields.Char('Passport No', help='Passport Number')
1
I guess you're looking for a computed field, but you should show us your code, this way we'll be able to help you better.forvas
but I think, computed field will not work outside its own classArsalan Sherwani
To copy a value from other model, a related field sounds the best option.forvas
how may I use related field hereArsalan Sherwani

1 Answers

-1
votes

class hrEmployee (models.Model):

_inherit = "hr.employee"



passports_ids =  fields.One2many('hr.employee.passports', 'employee_id', 'Passport')          

class hr_employee_passports(models.Model):  
_name='hr.employee.passports'    
employee_id = fields.Many2one("hr.employee", "Employee" ,   ondelete="cascade")

@api.one
@api.onchange('passports_number')        
def set_passport(self):
    result={} 

    if self.passports_number:

       for obj in self.employee_id:    
           obj.passport_id=self.passports_number

    return res{}
 passports_number = fields.Char('Passport No', help='Passport Number')