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

How to return a list of values into a one2many field?

By
rosey
on 1/23/15, 7:32 AM 947 views

I have below list value, How can i return this list value into a one2many field?

I tried many ways but no output.

[{'current_location': (1, u'Location 1'), 'id': 60, 'location_type': u'own'}, {'current_location': (1, u'location 1'), 'id': 63, 'location_type': u'own'}]

My python code is :

ename = context.get('employee_id');

emp_obj = self.pool.get('hr.employee')
emp_name = emp_obj.search(cr, uid, [('name','=',ename)], context=context)
location_lines = []
location_ids = self.pool.get('employee.location').search(cr, uid, [('employee_id','=',emp_name)],limit=5)

In this location_ids all records based on employee_id  should be as a stored as list.

I want to display the values in list into my one2many field. I want to display the records. dont want to create or write.

I dont know how i overcome the situation. I just want to display values in location_ids into my one2many field in hr.employee. How can i do this using the button click function? Please help me.

 

 

 

 

hi

aci aisha
on 1/23/15, 7:36 AM

hi

rosey
on 1/23/15, 11:39 PM

What do you mean by return? Looking at your code, employee.location must be linked to hr.employee through employee_id. I hope emp_name is hr.employee's ID. If so, displaying location_ids in the view alone should displayed all employee.location that is linked to the particular hr.employee. The add functionality is also build in if you use one2many_list widget. Where are you implementing this? Within the on_change mechanism? If it is for on_change mechanism and you want to add a value, use [(0, 0, {'current_location':r['current_location'], 'location_type':r['location_type']})]

Ivan
on 1/24/15, 1:13 AM

I'm using button click. when i click the button, all records from the employee.location based on employee_id will display in the one2many field in hr.employee.

rosey
on 1/24/15, 1:26 AM

Then I would suggest that the view that shows the location to be made for model hr.employee and only display location_ids in the view. If you pass the current active hr.employee's ID to that view in the window action, it should display the locations automatically.

Ivan
on 1/24/15, 3:11 AM

hello

aci aisha
on 1/27/15, 11:53 PM

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: 1/23/15, 7:32 AM
Seen: 947 times
Last updated: 3/16/15, 8:10 AM