【问题标题】:two many2many fields with different partner两个many2many字段与不同的合作伙伴
【发布时间】:2017-11-27 10:15:29
【问题描述】:

我有两个应该与 res.partner 相关的字段 在 partner_ids 我想选择合作伙伴,而在 recipients_ids 我想选择另一个将获得文件副本的合作伙伴。在表单视图中,如果我更改 partner_ids 或 recipient_ids 两个字段都变得相同的问题。我该怎么做才能在这些领域选择不同的合作伙伴?

partners_ids = fields.Many2many('res.partner', string='Companys Names')
recipients_ids = fields.Many2many('res.partner', string='Copys for')

【问题讨论】:

    标签: openerp odoo-8 odoo-9 odoo-10


    【解决方案1】:

    您收到错误是因为这两个字段在 postgres 中的同一张表上工作 因为 odoo 为该名称创建一个表,如下所示:

        current_model_name_co_model_name_rel
    

    你的情况

        your_model_res_partner_rel
    

    所以你需要告诉 odoo 每个字段都有它自己的关系

    partners_ids = fields.Many2many('res.partner', # co_model
                                    'your_model_partners_rel', # relation name change your_model to much your model name
                                    string='Companys Names')
    recipients_ids = fields.Many2many('res.partner', 
                                    'your_model_recipients_rel', 
                                    string='Copys for')
    

    当您创建 m2m 字段时,最好通过 keyarguement 指定此值

            _name = 'my.model'
    
            # exmple
            user_ids = fields.Many2many(comodel_name='res.users', # name of the model
                                relation='my_model_users_rel', # name of relation in postgres
                                column1='session_id', # id reference to current mode
                                column2='user_id', # id reference to co_model
                                string='Allowed users')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 2011-04-03
      • 1970-01-01
      • 2010-09-17
      相关资源
      最近更新 更多