Odoo Help


Onchange function is showing error while save it - - - Python code error

on 10/8/14, 12:32 AM 1,813 views

I have two model, one is the base model - hr.employee, other one a custom model - employee.employee.

Employee(hr.employee) model contains a new field  named Project(many2one field - project.project)

Project(project.project)  model contains contains a new field named Location field(many2one field - location.location)


Three fields in employee.employee custom model.

employee_id' : fields.many2one('hr.employee','Employee Name'),
source_location':fields.related('employee_id','project_id',type='many2one',readonly=True,relation='location.location',string='Source Location'),
project':fields.related('employee_id','project_id',type='many2one',readonly=True,relation='project.project',string='Current Project'),


def on_change_employee_id(self, cr, uid, ids, employee_id, context=None):
          values1 = {}
          if not employee_id:
             return values1
          employee1 = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
          print employee1.project_id.name,employee1.project_id.location.name
            'source_location' : employee1.project_id.location and employee1.project_id.location.id or False,
            'project' : employee1.project_id and employee1.project_id.id or False,
          print "values1",values1
          return {'value' : values1}


I want to update source location and project when the employee onchange occurs. When i print before update and after update the values are correct, when i save the record source location shows wrong. what should be the error?







| 7 8 8
Thiruvananthapuram, India

Working as an Senior ODOO developer. http://in.linkedin.com/pub/remya-r/69/a23/298

On 10/8/14, 1:45 AM

'employee_id' : fields.many2one('hr.employee','Employee Name'), 

 'project' : fields.related('employee_id','project_id',type='many2one',readonly=True,relation='project.project',string='Project'),
'source_location' : fields.related('project','location',type='many2one',readonly=True,relation='location.location',string='Source Location'),


source_location':fields.related('employee_id','project_id','location',type='many2one',readonly=True,relation='location.location',string='Source Location'),

Hello Ramya, are you interested for Odoo works. If yes contact me on Mob/WhatsApp +91 8289 958 063. Mail: mdrosh90@gmail.com. Skype: mdrosh90

Mohammed Roshan
on 3/24/17, 6:34 AM

Vasiliy Birukov

--Vasiliy Birukov--
| 7 6 8
Russian Federation
--Vasiliy Birukov--

Help develop and implement any project on base Odoo.

Vasiliy Birukov
On 10/8/14, 12:57 AM

You wrong define field source_location, must be:

source_location':fields.related('employee_id','project_id','location',type='many2one',readonly=True,relation='location.location',string='Source Location'),

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/8/14, 12:32 AM
Seen: 1813 times
Last updated: 3/16/15, 8:10 AM