2
votes

i have two fields that should be related to res.partner in partner_ids i want to choose partner and in recipients_ids i want to choose another partner that will get a copy of the document. the problem that in form view if i change partner_ids or recipient_ids both fields became the same. how can i do that i can choose different partners in those fields?

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

1 Answers

2
votes

You are getting the error because the two field work on the same table in postgres because odoo create a table for that name like this:

    current_model_name_co_model_name_rel

in your case

    your_model_res_partner_rel

so you need to tell odoo that every field has it's own relation

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')

when you create m2m field it's better to specify this value by 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')