Odoo Help

0

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

By
rosey
on 1/23/15, 7:32 AM 1,214 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
1

Mohammed Amal

--Mohammed Amal--
793
| 4 2 6
Malappuram, India
--Mohammed Amal--

Email : mohammedamal.n@gmail.com

Mohammed Amal
On 4/25/17, 1:14 AM

Writing to a Many2one field :

(0, 0,  { values })    link to a new record that needs to be created with the given values dictionary
(1, ID, { values })    update the linked record with id = ID (write *values* on it)
(2, ID)                remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID)                cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID)                link to existing record with id = ID (adds a relationship)
(5)                    unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

In this case use (6, 0, [ids])

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.

Register

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)

Stats

Asked: 1/23/15, 7:32 AM
Seen: 1214 times
Last updated: 4/25/17, 1:14 AM