
from odoo import api, exceptions, fields, models, _


class ResPartner(models.Model):
    _inherit = 'res.partner'

    industry_id = fields.Many2one(string='Main Industry')

    secondary_industry_ids = fields.Many2many(
        comodel_name='res.partner.industry', string="Secondary Industries",
        domain="[('id', '!=', industry_id)]")

    @api.constrains('industry_id', 'secondary_industry_ids')
    def _check_industries(self):
        if self.industry_id in self.secondary_industry_ids:
            raise exceptions.ValidationError(
                _('The main industry must be different '
                  'from the secondary industries.'))


from odoo import api, exceptions, fields, models, _


class ResPartner(models.Model):
    _inherit = 'res.partner'

    industry_id = fields.Many2one(string='Main Industry')

    secondary_industry_ids = fields.Many2many(
        comodel_name='res.partner.industry', string="Secondary Industries",
        domain="[('id', '!=', industry_id)]")

    @api.constrains('industry_id', 'secondary_industry_ids')
    def _check_industries(self):
        for partner in self:
            if partner.industry_id in partner.secondary_industry_ids:
                raise exceptions.ValidationError(
                    _('The main industry must be different '
                      'from the secondary industries.'))

Make api constrains multi to avoid error when create a company with 2 contacts
partner_industry_Secondary: Make api constrains multi to avoid error when create a company with 2 contacts

  
  from odoo import api, exceptions, fields, models, _
  
  
  class ResPartner(models.Model):
      _inherit = 'res.partner'
  
      industry_id = fields.Many2one(string='Main Industry')
  
      secondary_industry_ids = fields.Many2many(
          comodel_name='res.partner.industry', string="Secondary Industries",
          domain="[('id', '!=', industry_id)]")
  
      @api.constrains('industry_id', 'secondary_industry_ids')
      def _check_industries(self):
+         for partner in self:
-         if self.industry_id in self.secondary_industry_ids:
+             if partner.industry_id in partner.secondary_industry_ids:
-             raise exceptions.ValidationError(
+                 raise exceptions.ValidationError(
-                 _('The main industry must be different '
+                     _('The main industry must be different '
-                   'from the secondary industries.'))
+                       'from the secondary industries.'))
  
Make api constrains multi to avoid error when create a company with 2 contacts
## Code Before:

from odoo import api, exceptions, fields, models, _


class ResPartner(models.Model):
    _inherit = 'res.partner'

    industry_id = fields.Many2one(string='Main Industry')

    secondary_industry_ids = fields.Many2many(
        comodel_name='res.partner.industry', string="Secondary Industries",
        domain="[('id', '!=', industry_id)]")

    @api.constrains('industry_id', 'secondary_industry_ids')
    def _check_industries(self):
        if self.industry_id in self.secondary_industry_ids:
            raise exceptions.ValidationError(
                _('The main industry must be different '
                  'from the secondary industries.'))

## Instruction:
Make api constrains multi to avoid error when create a company with 2 contacts
## Code After:

from odoo import api, exceptions, fields, models, _


class ResPartner(models.Model):
    _inherit = 'res.partner'

    industry_id = fields.Many2one(string='Main Industry')

    secondary_industry_ids = fields.Many2many(
        comodel_name='res.partner.industry', string="Secondary Industries",
        domain="[('id', '!=', industry_id)]")

    @api.constrains('industry_id', 'secondary_industry_ids')
    def _check_industries(self):
        for partner in self:
            if partner.industry_id in partner.secondary_industry_ids:
                raise exceptions.ValidationError(
                    _('The main industry must be different '
                      'from the secondary industries.'))
