[FIX] account: fix invoice count

Prior to this commit, the count distinct on move_id called in the read
group was not used correctly.

This commit uses the move_id:count_distinct result of the read_group,
which represents the number of distinct invoices.

See task-2469742

PR : #70527

task-2458135
This commit is contained in:
Thibault Libioulle
2021-09-06 10:41:14 +02:00
committed by Laurent Stukkens (LTU)
parent c5048ebc6a
commit 22cd824772
@@ -38,7 +38,7 @@ class AccountAnalyticAccount(models.Model):
('analytic_account_id', 'in', self.ids)
]
groups = self.env['account.move.line'].read_group(domain, ['move_id:count_distinct'], ['analytic_account_id'])
moves_count_mapping = dict((g['analytic_account_id'][0], g['analytic_account_id_count']) for g in groups)
moves_count_mapping = dict((g['analytic_account_id'][0], g['move_id']) for g in groups)
for account in self:
account.invoice_count = moves_count_mapping.get(account.id, 0)
@@ -51,7 +51,7 @@ class AccountAnalyticAccount(models.Model):
('analytic_account_id', 'in', self.ids)
]
groups = self.env['account.move.line'].read_group(domain, ['move_id:count_distinct'], ['analytic_account_id'])
moves_count_mapping = dict((g['analytic_account_id'][0], g['analytic_account_id_count']) for g in groups)
moves_count_mapping = dict((g['analytic_account_id'][0], g['move_id']) for g in groups)
for account in self:
account.vendor_bill_count = moves_count_mapping.get(account.id, 0)