This question has been flagged
1 Reply
4642 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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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.