| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo import _, fields, models |
| 4 |
from odoo.exceptions import AccessError |
| 5 |
|
| 6 |
|
| 7 |
class DigestDigest(models.Model): |
| 8 |
_inherit = 'digest.digest' |
| 9 |
|
| 10 |
kpi_all_sale_total = fields.Boolean('All Sales') |
| 11 |
kpi_all_sale_total_value = fields.Monetary(compute='_compute_kpi_sale_total_value') |
| 12 |
|
| 13 |
def _compute_kpi_sale_total_value(self): |
| 14 |
if not self.env.user.has_group('sales_team.group_sale_salesman_all_leads'): |
| 15 |
raise AccessError(_("Do not have access, skip this data for user's digest email")) |
| 16 |
|
| 17 |
self._calculate_company_based_kpi( |
| 18 |
'sale.report', |
| 19 |
'kpi_all_sale_total_value', |
| 20 |
date_field='date', |
| 21 |
additional_domain=[('state', 'not in', ['draft', 'cancel', 'sent'])], |
| 22 |
sum_field='price_total', |
| 23 |
) |
| 24 |
|
| 25 |
def _compute_kpis_actions(self, company, user): |
| 26 |
res = super()._compute_kpis_actions(company, user) |
| 27 |
res['kpi_all_sale_total'] = 'sale.report_all_channels_sales_action?menu_id=%s' % self.env.ref('sale.sale_menu_root').id |
| 28 |
return res |