You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.0 KiB

  1. # Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
  2. # Copyright 2016 Tecnativa S.L. - Vicent Cubells
  3. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo import _, api, exceptions, fields, models
  6. class ResPartner(models.Model):
  7. _inherit = "res.partner"
  8. industry_id = fields.Many2one(string="Main Industry")
  9. secondary_industry_ids = fields.Many2many(
  10. comodel_name="res.partner.industry",
  11. string="Secondary Industries",
  12. domain="[('id', '!=', industry_id)]",
  13. )
  14. @api.constrains("industry_id", "secondary_industry_ids")
  15. def _check_industries(self):
  16. for partner in self:
  17. if partner.industry_id in partner.secondary_industry_ids:
  18. raise exceptions.ValidationError(
  19. _(
  20. "The main industry must be different "
  21. "from the secondary industries."
  22. )
  23. )