summaryrefslogtreecommitdiff
path: root/addons/analytic
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-05-18 18:54:26 +0200
committerChristophe Simonis <chs@odoo.com>2018-05-18 18:54:26 +0200
commit021d0e6a98bb9baa0d554d4e8b5717c7893a7641 (patch)
tree8d22beaa1ef2c4cb3c14896645554f646f0ddc9d /addons/analytic
parent40e74240e83f680bbdd9624c14edef2201d96d17 (diff)
parentcabe0951af2e0a0fcad47fa7a9fe2ffa5e8701cf (diff)
[MERGE] forward port branch saas-14 up to cabe0951af2
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 916d4878144..de3bc507049 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))