From ee0f98590e521a1cfa90e3b846aab8d11dc11508 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 4 May 2011 16:52:33 +0200 Subject: [PATCH] [FIX] account: improved order of account_period in order to have the period for opening entries first and fixed in common report wizard the bug that was selecting entries from opening period too when we were printing entries from january to march (because of same date_start for january and opening period). Also fixed the query_get when giving the periods directly in the context (previously it was doing a very weird thing with the clause where_move_lines_by_date defined again and it was not compliant with the opening period new change) bzr revid: qdp-launchpad@openerp.com-20110504145233-icq3a40l9pahy7hm --- addons/account/account.py | 7 +++++-- addons/account/account_move_line.py | 10 +--------- addons/account/wizard/account_report_common.py | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index c11d7394100..a6e83308385 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -879,7 +879,7 @@ class account_period(osv.osv): _defaults = { 'state': 'draft', } - _order = "date_start" + _order = "date_start, special desc" def _check_duration(self,cr,uid,ids,context=None): obj_period = self.browse(cr, uid, ids[0], context=context) @@ -961,7 +961,10 @@ class account_period(osv.osv): raise osv.except_osv(_('Error'), _('You should have chosen periods that belongs to the same company')) if period_date_start > period_date_stop: raise osv.except_osv(_('Error'), _('Start period should be smaller then End period')) - return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)]) + #for period from = january, we want to exclude the opening period (but it has same date_from, so we have to check if period_from is special or not to include that clause or not in the search). + if period_from.special: + return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)]) + return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id), ('special', '=', False)]) account_period() diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 9eeea323fb1..8d920f12db3 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -68,7 +68,6 @@ class account_move_line(osv.osv): if state: if state.lower() not in ['all']: where_move_state= " AND "+obj+".move_id IN (SELECT id FROM account_move WHERE account_move.state = '"+state+"')" - if context.get('period_from', False) and context.get('period_to', False) and not context.get('periods', False): if initial_bal: period_company_id = fiscalperiod_obj.browse(cr, uid, context['period_from'], context=context).company_id.id @@ -82,14 +81,7 @@ class account_move_line(osv.osv): 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) - where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date < '" +first_period.date_start+"')" - # Find the old periods where date start of those periods less then Start period - periods = fiscalperiod_obj.search(cr, uid, [('date_start', '<', first_period.date_start)]) - periods = ','.join([str(x) for x in periods]) - if periods: - query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND id IN (%s)) %s %s" % (fiscalyear_clause, periods, 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 (%s)) %s %s" % (fiscalyear_clause, 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 (%s) AND date_start <= '%s' AND id NOT IN %s) %s %s" % (fiscalyear_clause, first_period.date_start, tuple(context['periods']), where_move_state, where_move_lines_by_date) else: ids = ','.join([str(x) for x in context['periods']]) query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND id IN (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date) diff --git a/addons/account/wizard/account_report_common.py b/addons/account/wizard/account_report_common.py index 7a8a0365208..6784e44f779 100644 --- a/addons/account/wizard/account_report_common.py +++ b/addons/account/wizard/account_report_common.py @@ -68,7 +68,7 @@ class account_common_report(osv.osv_memory): FROM account_period p LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id) WHERE f.id = %s - ORDER BY p.date_start ASC + ORDER BY p.date_start ASC, p.special ASC LIMIT 1) AS period_start UNION SELECT * FROM (SELECT p.id