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.

1

Is this python code correct? Shows NameError: name 'project_id' is not defined

By
Remya
on 2/4/14, 8:22 AM 1,119 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?

1
Mayur Maheshwari
On 2/5/14, 3:21 AM

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 !!!

give you python example related your question

Mayur Maheshwari
on 2/5/14, 5:47 AM

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

Mayur Maheshwari
on 2/6/14, 2:09 AM

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})

Remya
on 2/6/14, 2:11 AM

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

Remya
on 2/6/14, 2:12 AM

Please refer the above code & help me.

Remya
on 2/6/14, 2:12 AM
0

Maniganda

--Maniganda--
1038
| 5 7 7
Bangalore, India
--Maniganda--
Maniganda
On 2/7/14, 2:59 AM

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

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: 2/4/14, 8:22 AM
Seen: 1119 times
Last updated: 3/16/15, 8:10 AM