Skip to Content
Menu
This question has been flagged
2 Replies
7658 Views

I add this code as server action for hr.applicant. Call this in Automated action.

active_id = context.get('active_id')
    applicant_obj = self.pool.get('hr.applicant')
    project_obj = self.pool.get('x_project.details')
    if project_id:
       applicant_record = self.browse(cr, uid, ids, active_id, context=context)
       project_obj.create(cr, uid, project_id, {'x_project': applicant_record.x_project}, context=context)

i have added x_project in hr.applicant & x_project.details models. Then i want to write the value of x_project in hr.applicant & x_project in x_project.details models.

Is the code correct?

Avatar
Discard
Best Answer

In your code , you have get a active_id from the context but in if condition you checked project_id variable which is not defined above . according to me you need to browse a project_id from respected table [like : project.project or x_project.details] and once you get then after used it in your code anywhere ..

Hope you understated what you miss !!!

Avatar
Discard

give you python example related your question

Again your code is wrong . you used project_id but not defined anywhere so how value comes in your code for temporary use project_id = [1] in your code after active_id statement so you will get idea about what you missed

Author

active_id = context.get('active_id') applicant_obj = self.pool.get('hr.applicant') project_obj = self.pool.get('x_project.details') applicant_record = self.browse(cr, uid, ids, active_id, context=context) x_project_sr = project_obj .search(cr, uid, [('hr_applicant_id', '=', applicant_record .id)]) if not x_project_sr: project_obj.create(cr, uid, {'hr_applicant_id': applicant_record .id,'x_project_start_date':applicant_record.x_project_start_date, 'x_project_end_date':applicant_record.x_project_end_date})

Author

But the above code is overwriting the existing record. Each time i want to create a new record. Please help me.

Author

Please refer the above code & help me.

Best Answer

check your code Remya, project_obj.create(cr, uid, project_id, {'x_project': applicant_record.x_project}, context=context) 1) in create method we will be not passing the ids( project_id) 2)either change to write method and define the project_id = some list of value and then call write method

Avatar
Discard