digest.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, _
  4. from odoo.exceptions import AccessError
  5. class Digest(models.Model):
  6. _inherit = 'digest.digest'
  7. kpi_project_task_opened = fields.Boolean('Open Tasks')
  8. kpi_project_task_opened_value = fields.Integer(compute='_compute_project_task_opened_value')
  9. def _compute_project_task_opened_value(self):
  10. if not self.env.user.has_group('project.group_project_user'):
  11. raise AccessError(_("Do not have access, skip this data for user's digest email"))
  12. for record in self:
  13. start, end, company = record._get_kpi_compute_parameters()
  14. record.kpi_project_task_opened_value = self.env['project.task'].search_count([
  15. ('stage_id.fold', '=', False),
  16. ('create_date', '>=', start),
  17. ('create_date', '<', end),
  18. ('company_id', '=', company.id),
  19. ('display_project_id', '!=', False),
  20. ])
  21. def _compute_kpis_actions(self, company, user):
  22. res = super(Digest, self)._compute_kpis_actions(company, user)
  23. res['kpi_project_task_opened'] = 'project.open_view_project_all&menu_id=%s' % self.env.ref('project.menu_main_pm').id
  24. return res