我正在为 Odoo 18开发一个简单的模块。
我创建了以下模型(如文档中所示):
class Supplier(models.Model):
_name = "res.partner.supplier"
_inherit = "res.partner"
它给出以下错误:
TypeError: Many2many fields res.partner.supplier.channel_ids and res.partner.channel_ids use the same table and columns
我在 stackoverflow 上搜索了答案并发现了类似的问题:
我尝试实现建议的逻辑,但它不起作用。
此代码:
class Supplier(models.Model):
_name = "res.partner.supplier"
_inherit = "res.partner"
channel_ids = fields.Many2many(
comodel_name='mail.channel', # The target model
relation='mail_channel_res_partner_supplier', # The name of the relation table
column1='res_partner_supplier_id', # The column for cps.supplier
column2='channel_id', # The column for mail.channel
string="Channels"
)
我收到这些警告和错误:
WARNING db_101 odoo.fields: Field res.partner.supplier.channel_ids with unknown comodel_name 'mail.channel'
ERROR db_101 odoo.sql_db: bad query: b'ALTER TABLE "mail_message_res_partner_starred_rel" ADD FOREIGN KEY ("res_partner_supplier_id") REFERENCES "res_partner_supplier"("id") ON DELETE cascade'
ERROR: column "res_partner_supplier_id" referenced in foreign key constraint does not exist
psycopg2.errors.UndefinedColumn: column "res_partner_supplier_id" referenced in foreign key constraint does not exist
所以,似乎不再有“mail.channel”了。
请问有什么帮助吗?
请更改关系表名称,因为它已经存在
relation='mail_channel_res_partner_supplier2'