From 7b7f3fa76a822f05283e36b40bdbc58793f84570 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 15 Mar 2016 15:03:29 +0100 Subject: [PATCH] [FIX] account: filter out special periods When computing the balance, debit and/or credit, the opening period must be filtered out. Otherwise, the invoices which are still opened at the time of the period closing will be counted twice. opw-670584 --- addons/account/account.py | 2 +- addons/account/account_move_line.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index da19fcf7197..306bb18fef9 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -314,7 +314,7 @@ class account_account(osv.osv): res = {} null_result = dict((fn, 0.0) for fn in field_names) if children_and_consolidated: - aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) + aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=dict(context or {}, periods_special=False)) wheres = [""] if query.strip(): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index de9c9b7c630..30e90dda379 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -83,19 +83,23 @@ class account_move_line(osv.osv): context['periods'] = fiscalperiod_obj.build_ctx_periods(cr, uid, first_period, context['period_from']) else: context['periods'] = fiscalperiod_obj.build_ctx_periods(cr, uid, context['period_from'], context['period_to']) + if 'periods_special' in context: + periods_special = ' AND special = %s ' % bool(context.get('periods_special')) + else: + periods_special = '' if context.get('periods'): query_params['period_ids'] = tuple(context['periods']) if initial_bal: - query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s)" + where_move_state + where_move_lines_by_date + query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s" + periods_special + ")" + where_move_state + where_move_lines_by_date period_ids = fiscalperiod_obj.search(cr, uid, [('id', 'in', context['periods'])], order='date_start', limit=1) if period_ids and period_ids[0]: first_period = fiscalperiod_obj.browse(cr, uid, period_ids[0], context=context) query_params['date_start'] = first_period.date_start - query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND date_start <= %(date_start)s AND id NOT IN %(period_ids)s)" + where_move_state + where_move_lines_by_date + query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND date_start <= %(date_start)s AND id NOT IN %(period_ids)s" + periods_special + ")" + where_move_state + where_move_lines_by_date else: - query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND id IN %(period_ids)s)" + where_move_state + where_move_lines_by_date + query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND id IN %(period_ids)s" + periods_special + ")" + where_move_state + where_move_lines_by_date else: - query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s)" + where_move_state + where_move_lines_by_date + query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s" + periods_special + ")" + where_move_state + where_move_lines_by_date if initial_bal and not context.get('periods') and not where_move_lines_by_date: #we didn't pass any filter in the context, and the initial balance can't be computed using only the fiscalyear otherwise entries will be summed twice