Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3343 Представления

I'm trying to develop simple library app with Odoo but I get an error with manytomany relationship.

Here are classes:

class Book(models.Model):
    _name = "library.book"
    publisher_id = fields.Many2one(comodel_name="library.book.partner", string="Publisher")
    author_ids = fields.Many2many(comodel_name="library.book.partner", relation='library_book_profile_partner_authors', column1='book_id', column2='partner_id', string="Authors")
class Partner(models.Model):
    _name = "library.book.partner"
    _inherit = "res.partner"
    published_book_ids = fields.One2many("library.book", "publisher_id", string="Published Books")
    book_ids = fields.Many2many("library.book", 'partner_books', 'book_id', 'partner_id', string="Authored Books")

This is the error I always get when installing the app

TypeError: Many2many fields library.book.partner.channel_ids and res.partner.channel_ids use the same table and columns 

Someone can help to solve this please ?

Аватар
Отменить
Лучший ответ

You are creating a new object "library.book.partner" by inheriting "res.partner". That is all fields of res.partner will be available in library.book.partner apart from the new fields defined. Now there is a field called channel_ids is defined in res.partner in the mail module, this is a many2many field and a copy of this field will be there in library.book.partner, and both use the same table and columns. This is not allowed and creates the error, so you have to define a new channel_ids field with a different table name in your model.

Here is the field definition in res.partner model:-

    channel_ids = fields.Many2many('mail.channel', 'mail_channel_partner', 'partner_id', 'channel_id', string='Channels', copy=False)

One other issue is that for many2may fields author_ids and book_ids you are using different relation[table name]. Instead, use the same table name and column1, column2 inversed.


class Book(models.Model):
_name = "library.book"
publisher_id = fields.Many2one(comodel_name="library.book.partner", string="Publisher")
author_ids = fields.Many2many(comodel_name="library.book.partner", relation='library_book_profile_partner_authors', column1='book_id', column2='partner_id', string="Authors")

class Partner(models.Model):
_name = "library.book.partner"
_inherit = "res.partner"
published_book_ids = fields.One2many("library.book", "publisher_id", string="Published Books")
book_ids = fields.Many2many("library.book", 'library_book_profile_partner_authors', 'partner_id', 'book_id', string="Authored Books")

channel_ids = fields.Many2many('mail.channel', 'mail_channel_partner_book', 'partner_id', 'channel_id', string='Channels', copy=False)


Аватар
Отменить

Adding Channel_ids not work in my odoo 15

Please include more details of your error

Related Posts Ответы Просмотры Активность
1
окт. 22
3108
1
сент. 22
3193
1
авг. 22
2791
1
мар. 24
1773
1
дек. 23
2564