[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.
This commit is contained in:
committed by
Thibault Delavallée
parent
870b05f693
commit
1909a70cee
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="digest.digest_digest_default" model="digest.digest">
|
||||
<field name="kpi_all_sale_total">True</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from . import digest
|
||||
@@ -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
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="digest_digest_view_form" model="ir.ui.view">
|
||||
<field name="name">digest.digest.view.form.inherit.sale.order</field>
|
||||
<field name="model">digest.digest</field>
|
||||
<field name="inherit_id" ref="digest.digest_digest_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='kpi_sales']" position="attributes">
|
||||
<attribute name="string">Sales</attribute>
|
||||
<attribute name="groups">sales_team.group_sale_salesman_all_leads</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//group[@name='kpi_sales']" position="inside">
|
||||
<field name="kpi_all_sale_total"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user