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.

34 lines
1.1 KiB

  1. # Copyright 2021 Open Source Integrators
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import ValidationError
  5. class PartnerStage(models.Model):
  6. _name = "res.partner.stage"
  7. _description = "Contact Stage"
  8. _order = "sequence, id"
  9. name = fields.Char(required=True, translate=True)
  10. code = fields.Char()
  11. sequence = fields.Integer(help="Used to order the stages", default=10)
  12. fold = fields.Boolean()
  13. active = fields.Boolean(default=True)
  14. description = fields.Text(translate=True)
  15. is_default = fields.Boolean("Default state")
  16. state = fields.Selection(
  17. [("draft", "To Approve"), ("confirmed", "Approved"), ("cancel", "Archived")],
  18. string="Related State",
  19. default="confirmed",
  20. )
  21. _sql_constraints = [
  22. ("res_partner_stage_code_unique", "UNIQUE(code)", "Stage Code must be unique.")
  23. ]
  24. @api.constrains("is_default")
  25. def _check_default(self):
  26. if self.search_count([("is_default", "=", True)]) > 1:
  27. raise ValidationError(_("There should be only one default stage"))