digest.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  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_account_total_revenue = fields.Boolean('Revenue')
  8. kpi_account_total_revenue_value = fields.Monetary(compute='_compute_kpi_account_total_revenue_value')
  9. def _compute_kpi_account_total_revenue_value(self):
  10. if not self.env.user.has_group('account.group_account_invoice'):
  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. self._cr.execute('''
  15. SELECT -SUM(line.balance)
  16. FROM account_move_line line
  17. JOIN account_move move ON move.id = line.move_id
  18. JOIN account_account account ON account.id = line.account_id
  19. WHERE line.company_id = %s AND line.date > %s::DATE AND line.date <= %s::DATE
  20. AND account.internal_group = 'income'
  21. AND move.state = 'posted'
  22. ''', [company.id, start, end])
  23. query_res = self._cr.fetchone()
  24. record.kpi_account_total_revenue_value = query_res and query_res[0] or 0.0
  25. def _compute_kpis_actions(self, company, user):
  26. res = super(Digest, self)._compute_kpis_actions(company, user)
  27. res['kpi_account_total_revenue'] = 'account.action_move_out_invoice_type&menu_id=%s' % self.env.ref('account.menu_finance').id
  28. return res