[IMP] Account move line: If we want to fiscal year to be empty in query for the condi...
authorMustufa Rangwala <mra@mra-laptop>
Thu, 22 Jul 2010 04:43:18 +0000 (10:13 +0530)
committerMustufa Rangwala <mra@mra-laptop>
Thu, 22 Jul 2010 04:43:18 +0000 (10:13 +0530)
[FIX] account report common

bzr revid: mra@mra-laptop-20100722044318-5s38i3y0dn138m5r

addons/account/account_move_line.py
addons/account/wizard/account_report_common.py

index f3739a9..4674064 100644 (file)
@@ -37,8 +37,10 @@ class account_move_line(osv.osv):
         fiscalperiod_obj = self.pool.get('account.period')
         fiscalyear_ids = []
         fiscalperiod_ids = []
-        if not context.get('fiscalyear', False):
+        if not context.get('fiscalyear', False) and not context.get('empty_fy_allow', False):
             fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
+        elif context.get('empty_fy_allow', False):
+            fiscalyear_ids = context['fiscalyear']
         else:
             fiscalyear_ids = [context['fiscalyear']]
 
@@ -55,10 +57,9 @@ class account_move_line(osv.osv):
             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']])
-            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)
+            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)
 
@@ -682,7 +683,7 @@ class account_move_line(osv.osv):
             account_id = line['account_id']['id']
             partner_id = (line['partner_id'] and line['partner_id']['id']) or False
         writeoff = debit - credit
-        
+
         # Ifdate_p in context => take this date
         if context.has_key('date_p') and context['date_p']:
             date=context['date_p']
index 95376b4..85f65bc 100644 (file)
@@ -116,6 +116,7 @@ class account_common_report(osv.osv_memory):
             context = {}
         result = {}
         period_obj = self.pool.get('account.period')
+        fiscal_obj = self.pool.get('account.fiscalyear')
         result['fiscalyear'] = 'fiscalyear_id' in data['form'] and data['form']['fiscalyear_id'] or False
         result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False
         result['chart_account_id'] = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] or False
@@ -131,6 +132,10 @@ class account_common_report(osv.osv_memory):
             result['periods'] = self._build_periods(cr, uid, data['form']['period_from'], data['form']['period_to'])
             first_period = self.pool.get('account.period').search(cr, uid, [], order='date_start', limit=1)[0]
             result_initial_bal['periods'] = self._build_periods(cr, uid, first_period, data['form']['period_from'])
+        else:
+            fiscal_date_start = fiscal_obj.browse(cr, uid, [data['form']['fiscalyear_id']], context=context)[0].date_start
+            result_initial_bal['empty_fy_allow'] = True #Improve me => there should be something generic in account.move.line -> query get
+            result_initial_bal['fiscalyear'] = fiscal_obj.search(cr, uid, [('date_stop', '<', fiscal_date_start), ('state', '=', 'draft')], context=context)
         return result, result_initial_bal
 
     def _print_report(self, cr, uid, ids, data, query_line, context=None):