From 1e1d7f9f6d5b30d0c4f21a54ecd3bee06a6de068 Mon Sep 17 00:00:00 2001 From: Kunjal Date: Fri, 6 Jul 2018 15:49:42 +0530 Subject: [PATCH] [ADD] : Added Upstream Patch for Analytic. --- addons/analytic/models/analytic_account.py | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index d3c65f4e..4e00d792 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -21,21 +21,24 @@ class AccountAnalyticAccount(models.Model): @api.multi def _compute_debit_credit_balance(self): analytic_line_obj = self.env['account.analytic.line'] - domain = [('account_id', 'in', self.mapped('id'))] + domain = [('account_id', 'in', self.ids)] if self._context.get('from_date', False): domain.append(('date', '>=', self._context['from_date'])) if self._context.get('to_date', False): domain.append(('date', '<=', self._context['to_date'])) - account_amounts = analytic_line_obj.search_read(domain, ['account_id', 'amount']) - account_ids = set([line['account_id'][0] for line in account_amounts]) - data_debit = {account_id: 0.0 for account_id in account_ids} - data_credit = {account_id: 0.0 for account_id in account_ids} - for account_amount in account_amounts: - if account_amount['amount'] < 0.0: - data_debit[account_amount['account_id'][0]] += account_amount['amount'] - else: - data_credit[account_amount['account_id'][0]] += account_amount['amount'] + credit_groups = analytic_line_obj.read_group( + domain=domain + [('amount', '>=', 0.0)], + fields=['account_id', 'amount'], + groupby=['account_id'] + ) + data_credit = {l['account_id'][0]: l['amount'] for l in credit_groups} + debit_groups = analytic_line_obj.read_group( + domain=domain + [('amount', '<', 0.0)], + fields=['account_id', 'amount'], + groupby=['account_id'] + ) + data_debit = {l['account_id'][0]: l['amount'] for l in debit_groups} for account in self: account.debit = abs(data_debit.get(account.id, 0.0))