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

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

By
rosey
on 1/31/15, 6:57 AM 509 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
          emp_ids=[]
          for emp in emp_ids_browse:
              emp_ids.append(emp.id)
              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?

Ivan
on 2/2/15, 8:34 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/31/15, 6:57 AM
Seen: 509 times
Last updated: 3/16/15, 8:10 AM