diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 5c4de25465c..b93afede487 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -44,11 +44,17 @@ class account_move_line(osv.osv): fiscalyear_clause = (','.join([str(x) for x in fiscalyear_ids])) or '0' else: fiscalyear_clause = '%s' % context['fiscalyear'] + state=context.get('state',False) + where_move_state='' + 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+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s))" % (fiscalyear_clause, ids) + ids = ','.join([str(x) for x in context['periods']]) + return obj+".active AND "+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) else: - return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s))" % (fiscalyear_clause,) + return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) %s)" % (fiscalyear_clause,where_move_state) 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 9ffb5b0d588..4927fc32945 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -87,6 +87,7 @@ class account_balance(report_sxw.rml_parse): ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] ctx['target_move'] = form['target_move'] + ctx['state']=form['state'] accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx) def cmp_code(x, y): return cmp(x.code, y.code) diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py index 6017342b7bf..78187c703b9 100644 --- a/addons/account/report/aged_trial_balance.py +++ b/addons/account/report/aged_trial_balance.py @@ -53,7 +53,7 @@ class aged_trial_report(report_sxw.rml_parse): res = [] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': form['fiscalyear']}) + context={'fiscalyear': form['fiscalyear'],'state':form['state']}) self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \ "res_partner.name AS name, res_partner.ref AS code " \ "FROM res_partner, account_move_line AS line, account_account " \ @@ -128,7 +128,7 @@ class aged_trial_report(report_sxw.rml_parse): def _get_total(self, fiscalyear, company_id): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': fiscalyear}) + context={'fiscalyear': fiscalyear,'state':self.datas['form']['state']}) self.cr.execute("SELECT SUM(debit - credit) " \ "FROM account_move_line AS line, account_account " \ "WHERE (line.account_id = account_account.id) " \ @@ -145,7 +145,7 @@ class aged_trial_report(report_sxw.rml_parse): def _get_before(self, date, fiscalyear, company_id): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': fiscalyear}) + context={'fiscalyear': fiscalyear,'state':self.datas['form']['state']}) self.cr.execute("SELECT SUM(debit - credit) " \ "FROM account_move_line AS line, account_account " \ "WHERE (line.account_id = account_account.id) " \ @@ -163,7 +163,7 @@ class aged_trial_report(report_sxw.rml_parse): def _get_for_period(self, period, fiscalyear, company_id): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': fiscalyear}) + context={'fiscalyear': fiscalyear,'state':self.datas['form']['state']}) self.cr.execute("SELECT SUM(debit - credit) " \ "FROM account_move_line AS line, account_account " \ "WHERE (line.account_id = account_account.id) " \ diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index 300a16c7ca7..90a787ab245 100644 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -107,6 +107,7 @@ class general_ledger(report_sxw.rml_parse): ctx = self.context.copy() ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] + ctx['state']=form['state'] query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit "\ "FROM account_move_line l, account_journal j "\ @@ -126,6 +127,7 @@ class general_ledger(report_sxw.rml_parse): ctx = self.context.copy() ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] + ctx['state']=form['state'] query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ @@ -136,6 +138,7 @@ class general_ledger(report_sxw.rml_parse): ctx = self.context.copy() ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] + ctx['state']=form['state'] query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ @@ -148,6 +151,7 @@ class general_ledger(report_sxw.rml_parse): ctx = self.context.copy() ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] + ctx['state']=form['state'] query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ @@ -161,6 +165,7 @@ class general_ledger(report_sxw.rml_parse): ctx = self.context.copy() ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] + ctx['state']=form['state'] query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index e6c65380737..912e8396ef2 100644 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.py @@ -82,7 +82,7 @@ class partner_balance(report_sxw.rml_parse): return [] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \ "CASE WHEN sum(debit) > sum(credit) " \ @@ -120,7 +120,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( 'SELECT sum(debit) ' \ 'FROM account_move_line ' \ @@ -138,7 +138,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( 'SELECT sum(credit) ' \ 'FROM account_move_line ' \ @@ -156,7 +156,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( 'SELECT sum(debit-credit) ' \ 'FROM account_move_line ' \ @@ -175,7 +175,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( 'SELECT CASE WHEN sum(debit) > sum(credit) ' \ 'THEN sum(debit - credit) ' \ @@ -197,7 +197,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( 'SELECT CASE WHEN sum(debit) < sum(credit) ' \ 'THEN sum(credit - debit) ' \ diff --git a/addons/account/report/third_party_ledger.py b/addons/account/report/third_party_ledger.py index 79bc6d4cc86..bf060555e7e 100644 --- a/addons/account/report/third_party_ledger.py +++ b/addons/account/report/third_party_ledger.py @@ -49,7 +49,7 @@ class third_party_ledger(report_sxw.rml_parse): def preprocess(self, objects, data, ids): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': data['form']['fiscalyear']}) + context={'fiscalyear': data['form']['fiscalyear'],'state':data['form']['state']}) self.cr.execute( "SELECT DISTINCT line.partner_id " \ "FROM account_move_line AS line, account_account AS account " \ @@ -79,7 +79,7 @@ class third_party_ledger(report_sxw.rml_parse): def lines(self, partner): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \ "FROM account_move_line l " \ @@ -103,7 +103,7 @@ class third_party_ledger(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ @@ -119,7 +119,7 @@ class third_party_ledger(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ @@ -137,7 +137,7 @@ class third_party_ledger(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ @@ -155,7 +155,7 @@ class third_party_ledger(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear']}) + context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ diff --git a/addons/account/wizard/wizard_account_balance_report.py b/addons/account/wizard/wizard_account_balance_report.py index 09bc80ad523..a36dda780e8 100644 --- a/addons/account/wizard/wizard_account_balance_report.py +++ b/addons/account/wizard/wizard_account_balance_report.py @@ -35,12 +35,14 @@ dates_form = '''
''' dates_fields = { 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'help': 'Keep empty for all open fiscal year'}, - 'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'} + 'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}, + 'state':{'string':'State','type':'selection','selection': [('draft','Draft'), ('posted','Posted'),('all','All')],} } class wizard_report(wizard.interface): @@ -48,6 +50,7 @@ class wizard_report(wizard.interface): fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) data['form']['target_move'] = False + data['form']['state']='all' if context.has_key('target_move'): data['form']['target_move'] = context['target_move'] return data['form'] diff --git a/addons/account/wizard/wizard_aged_trial_balance.py b/addons/account/wizard/wizard_aged_trial_balance.py index 51ea5c1384f..ec00fabcaee 100644 --- a/addons/account/wizard/wizard_aged_trial_balance.py +++ b/addons/account/wizard/wizard_aged_trial_balance.py @@ -47,6 +47,8 @@ _aged_trial_form = """