Odoo Help


Doubt in Python code- How fetching values from one table and display it in another table's one2many field using button click?

on 1/31/15, 6:57 AM 891 views

When i click the Refresh button below function will call. This one2many field is in hr.employee model.

def button_click(self, cr, uid, ids, context=None):
          if context is None:
             context = {}         
          res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'employee_profile','action_project', context=context)
          res['context'] = context
          emp_ids_browse = self.browse(cr, uid, ids, context=context)[0].project_line_ids
// project_line_ids -- one2many field in hr.employee table. I have an employee_id field in the employee.project table. I want to sort the records based on employee ids. Want to display in the same page.Here the issue is emp_ids_browse didnt browse any records. I want to display all records based on employee_id.  But now it is displaying all employee records in all employee profile. How can i get values in emp_ids_browse and sorting will based on employee_id?


          print "emp_ids_browse",emp_ids_browse
          for emp in emp_ids_browse:
              print "emp_ids",emp_ids
              res['project_line_ids'] = [('id','in', emp_ids)]
          return res


I dont want to create as a new record. Just want to display the exiting records in employee.project to hr.employee, in each employee profile

So, the objective is to show "the same" one2many fields in 2 tables in different sorting order? Any reason why not "fix" the sorting order in the original field? I understand that you have hr.employee and employee.projects, linked by employee_id in employee.projects. Is the Refresh button in the view that belongs to hr.employee? If so, isn't sorting by employee_id will be meaningless anyway because for each hr.employee the project_line_ids will only have 1 employee_id?

on 2/2/15, 8:34 PM

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: 1/31/15, 6:57 AM
Seen: 891 times
Last updated: 3/16/15, 8:10 AM