Skip to content
Snippets Groups Projects
Commit 8f0e3be2 authored by jvm-odoo's avatar jvm-odoo Committed by fw-bot
Browse files

[FIX] sale: fix sales team goal not updated in CRM pipelines


Reproduce this issue

    - Install CRM & Sales
    - Create 2 sales team in CRM settings
    - Create some invoices and register payments for the 2 teams
    - Go in CRM > Sales > Team pipelines

    The invoicing amount is still 0 for both teams.

Cause

    - The `_compute_invoiced` method in `CrmTeam` models use a SQL
    query to retrieve the invoices lines but it returns an empty
    recordset because the dates are not right ordered.

    - The line balance are negatives values, doing a SUM() will always
      returns 0

This commit re-order the dates and invert the sign of line.balance.

OPW-2119819

closes odoo/odoo#40115

X-original-commit: 578dacc3
Signed-off-by: default avatarJason Van Malder <jasonvanmalder@users.noreply.github.com>
parent 1270eaad
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,7 @@ class CrmTeam(models.Model):
query = '''
SELECT
move.team_id AS team_id,
SUM(line.balance) AS amount_untaxed_signed
SUM(-line.balance) AS amount_untaxed_signed
FROM account_move move
LEFT JOIN account_move_line line ON line.move_id = move.id
WHERE move.type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund')
......@@ -90,7 +90,7 @@ class CrmTeam(models.Model):
GROUP BY move.team_id
'''
today = fields.Date.today()
params = [tuple(self.ids), fields.Date.to_string(today), fields.Date.to_string(today.replace(day=1))]
params = [tuple(self.ids), fields.Date.to_string(today.replace(day=1)), fields.Date.to_string(today)]
self._cr.execute(query, params)
data_map = dict((v[0], v[1]) for v in self._cr.fetchall())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment