Odoo Help


How can we view one2many datas in another form view using a button click?

on 1/23/15, 12:29 AM 2,465 views



I have two different menu: HR-Employee and another is Employee location. In Employee location i will add the locations against each employees. Then i need an extra addons- ie, i want to see the history of these employee locations in their, each employee profile. So i added employee.location model as one2many in my employee profile(hr.employee). And added a button click. For an example, i added 3 records of employee sam in Employee location. Next i select HR-employee and select sam, there is a one2many field in sam's(employee profile). Above to the one2many field there is button. when i click the button it will select 3 records from the employee.location table, and will just display the records in the one2many field. I need this requirement. When i display the records in hr.employee, the id should be the same no duplication is allowed. I just want to display records in the one2many field.

def button_dummy(self, cr, uid, ids, context=None):
          res = []
          valiue = {}
          print "employee",context,ids
          ename = context.get('employee_id');         
          emp_obj = self.pool.get('hr.employee')
          emp_name = emp_obj.search(cr, uid, [('name','=',ename)], context=context)
          print "emp_name",emp_name
          location_lines = []
          location_ids = self.pool.get('employee.location').search(cr, uid, [('employee_id','=',emp_name)],limit=5)
          for p in self.pool.get('employee.location').browse(cr, uid, location_ids):
            ## First i used this return to update the one2many field, but no output
          return res

         ## Second i used this return to update the one2many field, but no output

          return {'value': {'location_line_ids': location_lines}}

How can i display records into one2many field using button click?

First i created employee.location model. Then i call employee.location(one2many) model in hr.employee. In employee.location there is a many2one employee_id field to connect both the models.


<button name="button_dummy" string="Refresh" type="object" context="{'employee_id':name,'location_line_ids':location_line_ids}"/>                      
                         <field name="location_line_ids" options="{'reload_on_button': true}">

When i click the button above function will call and just display the employee location data for only displaying. I dont want to write the datas again, only want to display the datas in each employee profile using employee_id.


aci aisha
on 1/23/15, 1:57 AM

What happen,do you know the answer?

on 1/23/15, 2:13 AM

Anil R. Kesariya (Jupical Technologies)

--Anil R. Kesariya (Jupical Technologies)--
| 7 6 8
Rajkot, India
--Anil R. Kesariya (Jupical Technologies)--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya (Jupical Technologies)
On 1/23/15, 2:27 AM

Hello Rosey,

Here you go!

There are two ways to get display location in wizard.

1) If you are adding all the location via location menu it self not from Employee form than and you have the many2one field of employee model inside employee.location. than no need of one2many field you can directly display all the employee location of that employee from the employee form.

i) create new action for emloyee.location and pass domain.

    Add this domain and target in your action :

<field name="domain">[('employee_id','=','active_id')]</field>

<field name="target">new</field>

ii)  Add button with type="action" in employee form and pass the action id in button.

It will only pop the related location for that employee in new window.


2) If you already added one2many field in your hr.employee model and you also want to get display those location in your new window than,

i) Create One Transient Model and add one2many field inside. (for wizard)

ii) Define the view for Transient Model (for wizard)

iii) Add button in Employee form and Call the action of wizard)

iv) pass default value etiher from context or from your method for one2many field.

  Hope this idea will work for you.





Thanks for the reply. Can you please update my code? I'm newbie in python, so please help me to solve the issue

on 1/23/15, 3:49 AM

This is not about python code. You should take proper odoo technical training.

Anil R. Kesariya (Jupical Technologies)
on 1/23/15, 3:51 AM

In the second step, can you please explain? i have some doubts in that

on 1/23/15, 5:11 AM

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/23/15, 12:29 AM
Seen: 2465 times
Last updated: 3/16/15, 8:10 AM