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.

32 lines
920 B

  1. # Copyright 2019 Open Source Integrators
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class ResPartner(models.Model):
  5. _name = "res.partner"
  6. _inherit = ["res.partner", "tier.validation"]
  7. _tier_validation_manual_config = False
  8. state = fields.Selection(
  9. [("draft", "Draft"), ("confirmed", "Active"), ("cancel", "Archived")],
  10. string="Status",
  11. default="draft",
  12. )
  13. @api.model
  14. def create(self, vals):
  15. new = super().create(vals)
  16. if new.need_validation and new.state != "confirmed":
  17. new.active = False
  18. return new
  19. def write(self, vals):
  20. """
  21. Default `active` is False.
  22. It is set to True when State changes to confirmed.
  23. """
  24. if "state" in vals:
  25. vals["active"] = vals["state"] == "confirmed"
  26. return super().write(vals)