Odoo Help

Welcome!

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

0

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

By
rosey
on 10/8/14, 12:32 AM 1,270 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
          values1.update({
            '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?

 

 

 

2

Remya

--Remya--
5813
| 7 8 8
Thiruvananthapuram, India
--Remya--

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

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

or 

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

3

Vasiliy Birukov

--Vasiliy Birukov--
3446
| 6 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'),

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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