[ADD] : Added Upstream Patch for Analytic.
This commit is contained in:
parent
cc9a88e2d2
commit
1e1d7f9f6d
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user