Odoo Help


How to return or update a one2many field using button click?

on 1/16/15, 7:51 AM 3,506 views

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 return values into one2many field using button click?


Updated question:

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.

Already i added datas in employee.location using different form view. Now i just want to see the history of the employee location in the employee profile. For that

<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.



I have edited my ans, check it. Let me know if that works or not. You don't need any button click. Just put the field in as shown in my ans.

Emipro Technologies Pvt. Ltd.
on 1/17/15, 1:51 AM

Thanks for your reply. 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 each employee profile. So i added employee location as one2many in my employee profile. 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. Do you understand my requirement?

on 1/20/15, 2:01 AM

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 1/16/15, 8:09 AM

You will directly update the values using the 'write' method, returning 'value' will not work. This is not 'onchange' method.

1./ Also, here you tried to find the location based on the 'employee_id' which could be a many2one field and you have tried searching as 'employee_id' ,'=',emp_name, that is an integer value and you are trying to search by 'string' value. I am wondering whether this is working for you or not.

2./ Where does 'project_ids' came from in the loop? I think it should be 'location_ids'.

Anyways, try following:

for p in self.pool.get('employee.location').browse(cr, uid, project_ids):

Once everything is stored in location_lines then you have to update that value using 'write' method



I don't think you need any button click, just to display the employee location. System will autmatically display all those values based on the relation.
Just put your field as shown below in your view, wherever you need it.

<field name="location_line_ids">
<tree string="Employee Locations">
    <<Your Fields From The Model 'employee.location'>>


Hope this helps !!.

Thanks for your help. i don't know python. i just started with python coding.

on 1/17/15, 12:08 AM

Please see my updated question. Code is working, but i don't want to write the datas again. I just want to display the datas. Please help me. I dont know python, coding makes me more confusion, so please help me.

on 1/17/15, 12:52 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

2 follower(s)


Asked: 1/16/15, 7:51 AM
Seen: 3506 times
Last updated: 3/16/15, 8:10 AM