diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index b10ced65e88..176b1d2a8fb 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -32,11 +32,13 @@ class account_move_line(osv.osv): _name = "account.move.line" _description = "Journal Items" - def _query_get(self, cr, uid, obj='l', context={}): + def _query_get(self, cr, uid, obj='l', context=None): fiscalyear_obj = self.pool.get('account.fiscalyear') fiscalperiod_obj = self.pool.get('account.period') fiscalyear_ids = [] fiscalperiod_ids = [] + if context is None: + context = {} initial_bal = context.get('initial_bal', False) company_clause = "" if context.get('company_id', False): @@ -58,7 +60,7 @@ class account_move_line(osv.osv): if context.get('date_from', False) and context.get('date_to', False): if initial_bal: - where_move_lines_by_date = " AND " +obj+".move_id in ( select id from account_move where date < '"+context['date_from']+"')" + where_move_lines_by_date = " OR " +obj+".move_id in ( select id from account_move where date < '"+context['date_from']+"')" else: where_move_lines_by_date = " AND " +obj+".move_id in ( select id from account_move where date >= '" +context['date_from']+"' AND date <= '"+context['date_to']+"')" @@ -88,7 +90,7 @@ class account_move_line(osv.osv): 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) 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) %s %s)" % (fiscalyear_clause, where_move_state, where_move_lines_by_date) if context.get('journal_ids', False): query += ' AND '+obj+'.journal_id in (%s)' % ','.join(map(str, context['journal_ids']))