From 301373e01b91d67fcfc67bc18c0b8821868fac51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 8 Apr 2016 22:55:36 +0200 Subject: [PATCH] Manage start/end period context in Type.get_amount And fix selection of periods with start date equals end date. issue5466 issue5267 review20141002 --- account.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/account.py b/account.py index 6bc619d112..f31b8d9fde 100644 --- a/account.py +++ b/account.py @@ -226,6 +226,7 @@ class Type(ModelSQL, ModelView): def get_amount(cls, types, name): pool = Pool() Account = pool.get('account.account') + GeneralLedger = pool.get('account.general_ledger.account') res = {} for type_ in types: @@ -238,10 +239,16 @@ class Type(ModelSQL, ModelView): for type_ in childs: type_sum[type_.id] = Decimal('0.0') - accounts = Account.search([ - ('type', 'in', [t.id for t in childs]), - ('kind', '!=', 'view'), - ]) + start_period_ids = GeneralLedger.get_period_ids('start_%s' % name) + end_period_ids = GeneralLedger.get_period_ids('end_%s' % name) + period_ids = list( + set(end_period_ids).difference(set(start_period_ids))) + + with Transaction().set_context(periods=period_ids): + accounts = Account.search([ + ('type', 'in', [t.id for t in childs]), + ('kind', '!=', 'view'), + ]) for account in accounts: type_sum[account.type.id] += (account.debit - account.credit) @@ -1118,6 +1125,8 @@ class GeneralLedgerAccount(ModelSQL, ModelView): ('fiscalyear', '=', context.get('fiscalyear')), ('end_date', '<=', period.start_date), ]) + if period.start_date == period.end_date: + periods.append(period) if periods: period_ids = [p.id for p in periods] return period_ids