Odoo Help


write values in two different objects with one function.

on 10/19/13, 3:28 PM 1,679 views

I do this :

class hr_posting(osv.osv):

_name = 'hr.posting'
_inherit = ['mail.thread']
_description = 'Posting'    
_columns = {
    'name': fields.char('Description', size=64),
    'employee_id': fields.many2one('hr.employee', 'Employee'),
    'state': fields.selection([
        ('draft', 'Draft'),
        ('confirm', 'Confirm'),
        ('close', 'Close'),
    ], 'Status', select=True),
    'job_id': fields.many2one('hr.job', 'Source Job', required=True),


So i define view and workflow for this object. My need is to define a function which will write state 'confirm' and also write in the hr.employee.job_id field of the selected employee from the hr.posting object (field employee_id), the selected hr.posting.job_id.id Thanks.


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 10/21/13, 6:41 AM

Hello Benos20,

Yes you can write n number of objects, how you can write two objects in one object is given below:

employee_obj = self.pool.get('hr.employee') #Getting employee object

for post_rec in self.browse(cr, uid, ids, context=context): #browse Posting records

job_id = post_rec.job_id or False #Getting job_id selected in Posting 
employee_id = post_rec.employee_id and post_rec.employee_id.id or False #Getting employee_id selected in Posting
if employee_id and job_id: #update selected Employee with selected job in Posting
    employee_obj.write(cr, uid, [employee_id], {'job_id' : job_id}, context=context)

self.write(cr, uid, ids, {'state' : 'confirm'}, context=context) #Update Posting records as confirm(assumed field name is state)

Hope this helps!

Thanks, Serpent Consulting Services Pvt. Ltd.

Hello Serpent Consulting! Thanks for your great help. i modify this line like this and job_id = post_rec.job_id.id or False # Getting job_id selected in posting and everything run correctly.

on 10/23/13, 2:39 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

0 follower(s)


Asked: 10/19/13, 3:28 PM
Seen: 1679 times
Last updated: 3/16/15, 8:10 AM