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.

25 lines
892 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, fields, models
  6. class ResPartner(models.Model):
  7. _inherit = 'res.partner'
  8. phonecall_ids = fields.One2many(
  9. 'crm.phonecall', 'partner_id', string='Phone Calls')
  10. phonecall_count = fields.Integer(
  11. compute='_compute_phonecall_count', string='Number of Phonecalls',
  12. readonly=True)
  13. @api.depends('phonecall_ids')
  14. def _compute_phonecall_count(self):
  15. rg_res = self.env['crm.phonecall'].read_group(
  16. [('partner_id', 'in', self.ids)],
  17. ['partner_id'], ['partner_id'])
  18. for rg_re in rg_res:
  19. partner = self.browse(rg_re['partner_id'][0])
  20. partner.phonecall_count = rg_re['partner_id_count']