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.

29 lines
953 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", "partner_id", "Privacy consents",
  8. )
  9. privacy_consent_count = fields.Integer(
  10. "Consents",
  11. compute="_compute_privacy_consent_count",
  12. help="Privacy consent requests amount",
  13. )
  14. @api.depends("privacy_consent_ids")
  15. def _compute_privacy_consent_count(self):
  16. """Count consent requests."""
  17. self.privacy_consent_count = 0
  18. groups = self.env["privacy.consent"].read_group(
  19. [("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"],
  20. )
  21. for group in groups:
  22. self.browse(group["partner_id"][0]).privacy_consent_count = group[
  23. "partner_id_count"
  24. ]