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

Why is KeyError: 'teacher_id' ?

By
Shivam Mahajan
on 12/23/15, 1:15 AM 1,409 views

class Teachers(models.Model):

_name = 'academy.teachers'

name = fields.Char()

course_ids = fields.One2many('product.template','teacher_id', string="Courses")


class Courses(models.Model):

_name = 'academy.courses'

_inherit = 'product.template'

name = fields.Char()

teacher_id=fields.Many2one('academy.teachers', string="Teacher")



0

Axel Mendoza

--Axel Mendoza--
10205
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/23/15, 1:40 AM

@Shivam Mahajan
Your error is because in your Courses class you are creating a new model 'academy.courses' using the model 'product.template' as a prototype. You are not extending the model 'product.template' with the field teacher_id and in your class Teachers you have the field course_ids as a one2many relation with the model 'product.template', that require a field named 'teacher_id' as a many2one to 'academy.teachers' in 'product.template'. 
To fix it you have two options, depending of what you need to do

1- You can change this:

course_ids = fields.One2many('product.template','teacher_id', string="Courses")

to this:

course_ids = fields.One2many('academy.courses','teacher_id', string="Courses")

 
2- Or you can change this:

class Courses(models.Model):

_name = 'academy.courses'

_inherit = 'product.template'

To this:

class Courses(models.Model):

_inherit = 'product.template'

Only use one of the two options. The #1 will keep the prototype inheritance from the model 'product.template' but fix the relation and the #2 will extends the model 'product.template' with the field teacher_id

Your choice

@Axel ..Thanks a lot for the help......It really works

Shivam Mahajan
on 12/23/15, 2:48 AM

Happy to help you, thanks me with an upvote and accept the answer

Axel Mendoza
on 12/23/15, 2:58 AM
0

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 12/23/15, 2:00 AM

Hi Shivam,

This type of error occurs if you did not add correct dependency in your module. 

Please check depends in __openerp__.py file in your module. Here in this case add 'product' because you are inheriting product.template

 

'depends': ['base','product',],


Hope this helps.


 

Hi Baiju , Thanks a lot for the response .But I am satisfied by the answer of Axel

Shivam Mahajan
on 12/23/15, 2:49 AM

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

1 follower(s)

Stats

Asked: 12/23/15, 1:15 AM
Seen: 1409 times
Last updated: 2/23/16, 2:28 AM