Skip to Content
Menu
This question has been flagged
3 Replies
2555 Views

My field 

employee_id = fields.Many2one(comodel_name="hr.employee", string="Employee", required=True, default=_get_employee_id, )
manage_id = fields.Char(string="Manager",required = True,)

I try like this, but  It's wrong
@api.onchange('manage_id')
   def _onchange_manager(self):
    self.employee_id.Manager=self.manage_id

  
Avatar
Discard
Can you give me example ?

Vào Th 4, 2 thg 1, 2019 vào lúc 09:48 Cybrosys Techno Solutions Pvt.Ltd <odoo@cybrosys.com> đã viết:

Using the onchange you can update/write only the current model


Sent by Odoo S.A. using Odoo.

These tips help you to get the basic idea about customization in odoo

https://learnopenerp.tumblr.com/

Best Answer

Better you should try it in create and write method.

@api.multi
def create(self, vals):
    if vals.get('manage_id') and vals.get('employee_id'):
        self.env['hr.employee'].browse(vals.get('employee_id')).Manager = vals.get(manage_id)
    return super(class_name, self).create(vals)
Avatar
Discard
Best Answer
@api.onchange('manage_id')
   def _onchange_manager(self):
    self.employee_id.write({'Manager':self.manage_id})
Avatar
Discard

Onchange methods trigger on the client side. So better to avoid any database operations. Better to use create/write method instead.