Before this commit, if two or more lines in sale_report had the same value as price_total, they were group together in _compute_kpi_sale_total_value and included in output sum only once. That leads to incorrect values in digest mail. This commit fixes that issue by changing grouping column from price_total to company_id. Steps to reproduce the issue: ---------------------------- 1. Send Digest Mail for database and check values in it (assume we have both All Sales KPI and PoS KPI). 2. Create several sale_order_line and/or pos_order_line with exactly the same price_total (for example: 5 PoS transaction, each one for one product of value 10000). 2. Send Digest Mail again and check values in it. Current behavior: ----------------- The All Sales KPI will increase by value of only one of lines (in our example: PoS KPI will increase by 50000 = 5*10000, All Sales KPI will increase by 10000) Expected behavior: ----------------- All Sales KPI should include all transactions from sale_report in given period of time (all sale_order_line and pos_order_line). opw-2938952 closes odoo/odoo#105248 X-original-commit: 804c485f6afe98c5d63cfe91ce65e0a8352fc92e Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
# -*- 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([
|
|
('date', '>=', start),
|
|
('date', '<', end),
|
|
('state', 'not in', ['draft', 'cancel', 'sent']),
|
|
('company_id', '=', company.id)], ['price_total'], ['company_id'])
|
|
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
|