Skip to content
Permalink
Browse files

[FIX] crm_enterprise: prorated revenue

- Create 2 `crm.lead`:
  Expected Revenue: 100; Probability: 99 %
  Expected Revenue: 200; Probability: 0 %
- Go to Reporting > Sales Channels

The amount displayed next to 'Open Opportunities' is 148.5 is instead of
99.

opw-1947975

closes #32011

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information...
nim-odoo committed Mar 21, 2019
1 parent 723c657 commit 3a76d4570645abab55ab11253b7a0d68635e2ba0
Showing with 9 additions and 4 deletions.
  1. +9 −4 addons/crm/models/crm_team.py
@@ -50,13 +50,18 @@ def _compute_unassigned_leads_count(self):
team.unassigned_leads_count = counts.get(team.id, 0)

def _compute_opportunities(self):
opportunity_data = self.env['crm.lead'].read_group([
opportunity_data = self.env['crm.lead'].search([
('team_id', 'in', self.ids),
('probability', '<', 100),
('type', '=', 'opportunity'),
], ['planned_revenue', 'probability', 'team_id'], ['team_id'])
counts = {datum['team_id'][0]: datum['team_id_count'] for datum in opportunity_data}
amounts = {datum['team_id'][0]: (datum['planned_revenue'] * datum['probability'] / 100) for datum in opportunity_data}
]).read(['planned_revenue', 'probability', 'team_id'])
counts = {}
amounts = {}
for datum in opportunity_data:
counts.setdefault(datum['team_id'][0], 0)
amounts.setdefault(datum['team_id'][0], 0)
counts[datum['team_id'][0]] += 1
amounts[datum['team_id'][0]] += (datum.get('planned_revenue', 0) * datum.get('probability', 0) / 100.0)
for team in self:
team.opportunities_count = counts.get(team.id, 0)
team.opportunities_amount = amounts.get(team.id, 0)

0 comments on commit 3a76d45

Please sign in to comment.
You can’t perform that action at this time.