diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 084185a6462..354f721db5a 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -40,16 +40,22 @@ class account_move_line(osv.osv): else: fiscalyear_clause = '%s' % context['fiscalyear'] state=context.get('state',False) - where_move_state='' + where_move_state = '' + where_move_lines_by_date = '' + + if context.get('date_from', False) and context.get('date_to', False): + 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']+"')" + 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('periods', False): ids = ','.join([str(x) for x in context['periods']]) - return obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s" % (fiscalyear_clause, ids,where_move_state) + return 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: - return obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) %s)" % (fiscalyear_clause,where_move_state) + return 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) def default_get(self, cr, uid, fields, context={}): data = self._default_get(cr, uid, fields, context) diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 64db67efea5..e74ad786365 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -127,6 +127,8 @@ class account_balance(report_sxw.rml_parse): ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] elif form['state']== 'bydate': + ctx['date_from'] = form['date_from'] + ctx['date_to'] = form['date_to'] self.transform_date_into_date_array(form) elif form['state'] == 'all' : self.transform_both_into_date_array(form)