utm.py 748 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models
  4. class UtmCampaign(models.Model):
  5. _inherit = ['utm.campaign']
  6. _description = 'UTM Campaign'
  7. click_count = fields.Integer(string="Number of clicks generated by the campaign", compute="_compute_clicks_count")
  8. def _compute_clicks_count(self):
  9. click_data = self.env['link.tracker.click']._read_group(
  10. [('campaign_id', 'in', self.ids)],
  11. ['campaign_id'], ['campaign_id'])
  12. mapped_data = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in click_data}
  13. for campaign in self:
  14. campaign.click_count = mapped_data.get(campaign.id, 0)