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.

31 lines
959 B

  1. # Copyright 2018 Tecnativa - Jairo Llopis
  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. _inherit = "res.partner"
  6. privacy_consent_ids = fields.One2many(
  7. "privacy.consent",
  8. "partner_id",
  9. "Privacy consents",
  10. )
  11. privacy_consent_count = fields.Integer(
  12. "Consents",
  13. compute="_compute_privacy_consent_count",
  14. help="Privacy consent requests amount",
  15. )
  16. @api.depends("privacy_consent_ids")
  17. def _compute_privacy_consent_count(self):
  18. """Count consent requests."""
  19. groups = self.env["privacy.consent"].read_group(
  20. [("partner_id", "in", self.ids)],
  21. ["partner_id"],
  22. ["partner_id"],
  23. )
  24. for group in groups:
  25. self.browse(group["partner_id"][0], self._prefetch) \
  26. .privacy_consent_count = group["partner_id_count"]