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

write values in two different objects with one function.

By
Koffi KPONOUGLO
on 10/19/13, 3:28 PM 1,054 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),

hr_posting()

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.

1

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 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.

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

0 follower(s)

Stats

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