Skip to Content
Menu
This question has been flagged

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 ?

Avatar
Discard
Best Answer

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)


Avatar
Discard

Adding Channel_ids not work in my odoo 15

Please include more details of your error

Related Posts Replies Views Activity
1
Oct 22
2155
1
Sep 22
2093
1
Aug 22
1778
1
Mar 24
502
1
Dec 23
995