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.

56 lines
1.8 KiB

  1. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class TierReview(models.Model):
  5. _name = "tier.review"
  6. _description = "Tier Review"
  7. name = fields.Char(related="definition_id.name", readonly=True)
  8. status = fields.Selection(
  9. selection=[("pending", "Pending"),
  10. ("rejected", "Rejected"),
  11. ("approved", "Approved")],
  12. default="pending",
  13. )
  14. model = fields.Char(string='Related Document Model', index=True)
  15. res_id = fields.Integer(string='Related Document ID', index=True)
  16. definition_id = fields.Many2one(
  17. comodel_name="tier.definition",
  18. )
  19. review_type = fields.Selection(
  20. related="definition_id.review_type", readonly=True,
  21. )
  22. reviewer_id = fields.Many2one(
  23. related="definition_id.reviewer_id", readonly=True,
  24. )
  25. reviewer_group_id = fields.Many2one(
  26. related="definition_id.reviewer_group_id", readonly=True,
  27. )
  28. reviewer_ids = fields.Many2many(
  29. string="Reviewers", comodel_name="res.users",
  30. compute="_compute_reviewer_ids", store=True,
  31. )
  32. sequence = fields.Integer(string="Tier")
  33. done_by = fields.Many2one(
  34. comodel_name="res.users",
  35. )
  36. requested_by = fields.Many2one(
  37. comodel_name="res.users",
  38. )
  39. reviewed_date = fields.Datetime(string='Validation Date')
  40. @api.model
  41. def _get_reviewer_fields(self):
  42. return ['reviewer_id', 'reviewer_group_id', 'reviewer_group_id.users']
  43. @api.multi
  44. @api.depends(lambda self: self._get_reviewer_fields())
  45. def _compute_reviewer_ids(self):
  46. for rec in self:
  47. rec.reviewer_ids = rec._get_reviewers()
  48. def _get_reviewers(self):
  49. return self.reviewer_id + self.reviewer_group_id.users