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.

83 lines
2.5 KiB

  1. # Copyright 2019 Myceliandre - Nicolas JEUDY
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class PersonalDataCategory(models.Model):
  5. _name = "privacy.personal.category"
  6. _description = "Personal Data category"
  7. _parent_name = "parent_id"
  8. _parent_store = True
  9. _rec_name = "complete_name"
  10. _order = "complete_name"
  11. name = fields.Char("Name", index=True, required=True, translate=True)
  12. description = fields.Html(
  13. translate=True, help="Give more example, explanation of personal data"
  14. )
  15. complete_name = fields.Char(
  16. "Complete Name", compute="_compute_complete_name", store=True
  17. )
  18. parent_id = fields.Many2one(
  19. "privacy.personal.category", "Parent Category", index=True, ondelete="cascade"
  20. )
  21. parent_path = fields.Char(index=True)
  22. type = fields.Selection(
  23. [("common", "Common"), ("risk", "High Risk"), ("sensitive", "Sensitive")],
  24. string="Type",
  25. default="common",
  26. required=True,
  27. )
  28. child_id = fields.One2many(
  29. "privacy.personal.category", "parent_id", "Child Categories"
  30. )
  31. @api.depends("name", "parent_id.complete_name")
  32. def _compute_complete_name(self):
  33. for category in self:
  34. if category.parent_id:
  35. category.complete_name = "%s / %s" % (
  36. category.parent_id.complete_name,
  37. category.name,
  38. )
  39. else:
  40. category.complete_name = category.name
  41. @api.constrains("parent_id")
  42. def _check_category_recursion(self):
  43. if not self._check_recursion():
  44. raise ValidationError(_("You cannot create recursive categories."))
  45. return True
  46. @api.model
  47. def name_create(self, name):
  48. return self.create({"name": name}).name_get()[0]
  49. class PersonalData(models.Model):
  50. _name = "privacy.personal.data"
  51. _description = "Personal Data"
  52. active = fields.Boolean(
  53. default=True,
  54. index=True,
  55. )
  56. name = fields.Char(
  57. index=True,
  58. required=True,
  59. translate=True,
  60. )
  61. description = fields.Html(translate=True, help="Data list used in activity")
  62. categ_id = fields.Many2one(
  63. "privacy.personal.category",
  64. string="Category",
  65. domain=[("child_id", "=", False)],
  66. )
  67. type = fields.Selection(
  68. related="categ_id.type",
  69. )
  70. data_month_before_erasing = fields.Integer("Erasing delay (month)")
  71. legal_erasing = fields.Integer("Legal Erasing (month)")