Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6115 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 19
10931
1
thg 3 15
5764
2
thg 12 20
4664
1
thg 7 19
4446
2
thg 4 19
6418