0

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

pppery
  • 3,731
  • 22
  • 33
  • 46

1 Answers1

0

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.

Kenly
  • 24,317
  • 7
  • 44
  • 60
  • i did that but now i got another error: Traceback (most recent call last): File "/opt/odoo15/odoo/odoo/http.py", line 644, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo15/odoo/odoo/http.py", line 302, in _handle_exception raise exception.with_traceback(None) from new_cause psycopg2.errors.UndefinedColumn: column "academy_courses_id" referenced in foreign key constraint does not exist – Артем Колос Mar 24 '22 at 15:34
  • The `product.template` model is hard coded in product and attributes models, in fields and functions so you can't inherit the product template model using only the `_inherit` attribute – Kenly Mar 25 '22 at 22:49