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
983 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Tecnativa - Jairo Llopis
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class ResPartner(models.Model):
  6. _inherit = "res.partner"
  7. privacy_consent_ids = fields.One2many(
  8. "privacy.consent",
  9. "partner_id",
  10. "Privacy consents",
  11. )
  12. privacy_consent_count = fields.Integer(
  13. "Consents",
  14. compute="_compute_privacy_consent_count",
  15. help="Privacy consent requests amount",
  16. )
  17. @api.depends("privacy_consent_ids")
  18. def _compute_privacy_consent_count(self):
  19. """Count consent requests."""
  20. groups = self.env["privacy.consent"].read_group(
  21. [("partner_id", "in", self.ids)],
  22. ["partner_id"],
  23. ["partner_id"],
  24. )
  25. for group in groups:
  26. self.browse(group["partner_id"][0], self._prefetch) \
  27. .privacy_consent_count = group["partner_id_count"]