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.

28 lines
971 B

  1. # Copyright 2021 Camptocamp SA
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
  3. from odoo import _, api, models
  4. from odoo.exceptions import ValidationError
  5. class ResPartnerIdNumber(models.Model):
  6. _inherit = "res.partner.id_number"
  7. _description = "Partner ID Number"
  8. _order = "name"
  9. @api.constrains("name", "category_id")
  10. def validate_id_number(self):
  11. super().validate_id_number()
  12. for rec in self:
  13. if not rec.category_id.has_unique_numbers:
  14. continue
  15. count = self.search_count(
  16. [("name", "=", rec.name), ("category_id", "in", rec.category_id.ids)]
  17. )
  18. if count > 1:
  19. raise ValidationError(
  20. _(
  21. "The Id {} in the category {} could not be created because "
  22. "it already exists"
  23. ).format(rec.name, rec.category_id.name)
  24. )