summaryrefslogtreecommitdiff
path: root/addons/analytic
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-05-18 18:53:56 +0200
committerChristophe Simonis <chs@odoo.com>2018-05-18 18:53:56 +0200
commitcabe0951af2e0a0fcad47fa7a9fe2ffa5e8701cf (patch)
tree4932769edceb7c93eeb15ded48937acaea5bb046 /addons/analytic
parenta1a03792b6fb7a029a805976512f13ed13c2c6b9 (diff)
parent9001a75f23c014e744fc1853190297eed4c47438 (diff)
[MERGE] forward port branch 10.0 up to 9001a75f23c
Diffstat (limited to 'addons/analytic')
-rw-r--r--addons/analytic/models/analytic_account.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py
index 0a35ec1fc2a..8350e1a52fa 100644
--- a/addons/analytic/models/analytic_account.py
+++ b/addons/analytic/models/analytic_account.py
@@ -20,21 +20,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))