'Why I have error in Odoo while using product.template

I'm trying to run a test task from the site https://www.odoo.com/documentation/15.0/developer/howtos/website.html

models.py

from odoo import models, fields, api

 class Teachers(models.Model):
    _name = 'academy.teachers'

    name = fields.Char()
    biography = fields.Html()
    course_ids = fields.One2many('academy.courses', 'teacher_id', string="Courses")

 class Courses(models.Model):
    
    _name = 'academy.courses'
    _inherit = 'product.template'
    teacher_id = fields.Many2one('academy.teachers', string="Teacher")

but when start odoo i have error

TypeError: Many2many fields academy.courses.taxes_id and product.template.taxes_id use the same table and columns - - -

don't understand how to remove this error Бany2many fields academy.courses.taxes_id and product.template.taxes_id use the same table and columns



Solution 1:[1]

When you inherit the product.template models and set the _name attribute, Odoo will copy the fields with all their attributes, and in case of taxes_id, supplier_taxes_id and route_ids, the relation is set manually which will be the same in academy.courses model.

When Odoo will try to check whether other fields use the same schema it will fail and raise the error you see in the log.

Edit:

There are many references to product.template in model fields and methods. Even if you fix that error, the product_tmpl_id field still referece the product template model and this will prevent Odoo from creating any course.

When you change for example the product code it will check if the code is already used in product template model which is wrong.

Using only the _inherit attribute, you can`t inherit the product template model.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1