From 1909a70cee43755ddde782cd0268ad8f3ebe8627 Mon Sep 17 00:00:00 2001 From: Mitali Patel Date: Wed, 16 May 2018 12:00:55 +0530 Subject: [PATCH] [IMP] sale_management: implement digest KPIs / tips Purpose of this commit is to send sales details KPIs in digest email. Those are added in the default digest template. This commit is linked to task ID 30655 and PR #18318. --- addons/sale_management/__init__.py | 1 + addons/sale_management/__manifest__.py | 4 ++- addons/sale_management/data/digest_data.xml | 8 ++++++ addons/sale_management/models/__init__.py | 3 ++ addons/sale_management/models/digest.py | 28 +++++++++++++++++++ addons/sale_management/views/digest_views.xml | 17 +++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 addons/sale_management/data/digest_data.xml create mode 100644 addons/sale_management/models/__init__.py create mode 100644 addons/sale_management/models/digest.py create mode 100644 addons/sale_management/views/digest_views.xml diff --git a/addons/sale_management/__init__.py b/addons/sale_management/__init__.py index 086ab956265..5b04ef45b70 100644 --- a/addons/sale_management/__init__.py +++ b/addons/sale_management/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import models from odoo.api import Environment, SUPERUSER_ID diff --git a/addons/sale_management/__manifest__.py b/addons/sale_management/__manifest__.py index c4584b0acc9..f6c22179217 100644 --- a/addons/sale_management/__manifest__.py +++ b/addons/sale_management/__manifest__.py @@ -41,10 +41,12 @@ The Dashboard for the Sales Manager will include * Monthly Turnover (Graph) """, 'website': 'https://www.odoo.com/page/sales', - 'depends': ['sale', 'account_invoicing'], + 'depends': ['sale', 'account_invoicing', 'digest'], 'data': [ + 'data/digest_data.xml', 'views/sale_management_views.xml', 'views/sale_management_templates.xml', + 'views/digest_views.xml', ], 'application': True, 'uninstall_hook': 'uninstall_hook', diff --git a/addons/sale_management/data/digest_data.xml b/addons/sale_management/data/digest_data.xml new file mode 100644 index 00000000000..11f5d70fbb0 --- /dev/null +++ b/addons/sale_management/data/digest_data.xml @@ -0,0 +1,8 @@ + + + + + True + + + diff --git a/addons/sale_management/models/__init__.py b/addons/sale_management/models/__init__.py new file mode 100644 index 00000000000..5c69071ab19 --- /dev/null +++ b/addons/sale_management/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import digest diff --git a/addons/sale_management/models/digest.py b/addons/sale_management/models/digest.py new file mode 100644 index 00000000000..7ddf5d27d1f --- /dev/null +++ b/addons/sale_management/models/digest.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, _ +from odoo.exceptions import AccessError + + +class Digest(models.Model): + _inherit = 'digest.digest' + + kpi_all_sale_total = fields.Boolean('All Sales') + kpi_all_sale_total_value = fields.Monetary(compute='_compute_kpi_sale_total_value') + + def _compute_kpi_sale_total_value(self): + if not self.env.user.has_group('sales_team.group_sale_salesman_all_leads'): + raise AccessError(_("Do not have access, skip this data for user's digest email")) + for record in self: + start, end, company = record._get_kpi_compute_parameters() + all_channels_sales = self.env['sale.report'].read_group([ + ('confirmation_date', '>=', start), + ('confirmation_date', '<', end), + ('company_id', '=', company.id)], ['price_total'], ['price_total']) + record.kpi_all_sale_total_value = sum([channel_sale['price_total'] for channel_sale in all_channels_sales]) + + def compute_kpis_actions(self, company, user): + res = super(Digest, self).compute_kpis_actions(company, user) + res['kpi_all_sale_total'] = 'sale.report_all_channels_sales_action&menu_id=%s' % self.env.ref('sale.sale_menu_root').id + return res diff --git a/addons/sale_management/views/digest_views.xml b/addons/sale_management/views/digest_views.xml new file mode 100644 index 00000000000..1193758ed1d --- /dev/null +++ b/addons/sale_management/views/digest_views.xml @@ -0,0 +1,17 @@ + + + + digest.digest.view.form.inherit.sale.order + digest.digest + + + + Sales + sales_team.group_sale_salesman_all_leads + + + + + + +