在Odoo中更改其他类的字段数据

时间:2015-07-31 09:54:11

标签: python openerp odoo-8

我一直在Ubuntu 14.04下为Odoo8开发模块。我正在尝试将当前类的字段数据设置为其他类的字段数据。我试图分配值,但它没有显示在该其他类的字段上。在命令提示符上打印值时,它显示正确的值,但在Odoo字段上,文本框保持为空。有任何线索或建议吗?希望提出建议。请检查下面的代码

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 个答案:

答案 0 :(得分:-1)

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