From d6f88d7b0b709360573e726daeea7f7b2bf17f5f Mon Sep 17 00:00:00 2001 From: vra Date: Thu, 16 Sep 2010 14:43:12 +0530 Subject: [PATCH] [ADD] account: added account move filter in account journal report and wizard. bzr revid: vra@tinyerp.com-20100916091312-pokqkql1um4cb32g --- addons/account/report/account_journal.py | 48 ++++++++++++++++++- addons/account/report/account_journal.rml | 6 +-- .../wizard/account_report_print_journal.py | 5 +- .../account_report_print_journal_view.xml | 1 + 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/addons/account/report/account_journal.py b/addons/account/report/account_journal.py index 1ed15f60b6f..9f050756a5e 100644 --- a/addons/account/report/account_journal.py +++ b/addons/account/report/account_journal.py @@ -54,6 +54,7 @@ class journal_print(report_sxw.rml_parse, common_report_header): def set_context(self, objects, data, ids, report_type=None): new_ids = ids self.query_get_clause = '' + self.target_move = data['form'].get('target_move', 'all') if (data['model'] == 'ir.ui.menu'): new_ids = data['form'].get('active_ids', []) self.query_get_clause = 'AND ' @@ -66,6 +67,46 @@ class journal_print(report_sxw.rml_parse, common_report_header): self.period_ids, self.journal_ids = zip(*res) return super(journal_print, self).set_context(objects, data, ids, report_type=report_type) + def _sum_debit(self, period_id=False, journal_id=False): + if journal_id and isinstance(journal_id, int): + journal_id = [journal_id] + if period_id and isinstance(period_id, int): + period_id = [period_id] + if not journal_id: + journal_id = self.journal_ids + if not period_id: + period_id = self.period_ids + if not (period_id and journal_id): + return 0.0 + move_state = ['draft','posted'] + if self.target_move == 'posted': + move_state = ['posted'] + + self.cr.execute('SELECT SUM(debit) FROM account_move_line l , account_move am ' + 'WHERE l.move_id=am.id AND am.state IN %s AND l.period_id IN %s AND l.journal_id IN %s ' + self.query_get_clause + ' ', + (tuple(move_state), tuple(period_id), tuple(journal_id))) + return self.cr.fetchone()[0] or 0.0 + + def _sum_credit(self, period_id=False, journal_id=False): + if journal_id and isinstance(journal_id, int): + journal_id = [journal_id] + if period_id and isinstance(period_id, int): + period_id = [period_id] + if not journal_id: + journal_id = self.journal_ids + if not period_id: + period_id = self.period_ids + if not (period_id and journal_id): + return 0.0 + move_state = ['draft','posted'] + if self.target_move == 'posted': + move_state = ['posted'] + + self.cr.execute('SELECT SUM(l.credit) FROM account_move_line l, account_move am ' + 'WHERE l.move_id=am.id AND am.state IN %s AND l.period_id IN %s AND l.journal_id IN %s '+ self.query_get_clause+'', + (tuple(move_state), tuple(period_id), tuple(journal_id))) + return self.cr.fetchone()[0] or 0.0 + def lines(self, period_id, journal_id=False): if not journal_id: journal_id = self.journal_ids @@ -74,7 +115,12 @@ class journal_print(report_sxw.rml_parse, common_report_header): obj_mline = self.pool.get('account.move.line') self.cr.execute('update account_journal_period set state=%s where journal_id IN %s and period_id=%s and state=%s', ('printed', self.journal_ids, period_id, 'draft')) self.cr.commit() - self.cr.execute('SELECT id FROM account_move_line l WHERE period_id=%s AND journal_id IN %s ' + self.query_get_clause + ' ORDER BY '+ self.sort_selection + '' ,(period_id, tuple(journal_id) )) + + move_state = ['draft','posted'] + if self.target_move == 'posted': + move_state = ['posted'] + + self.cr.execute('SELECT l.id FROM account_move_line l, account_move am WHERE l.move_id=am.id AND am.state IN %s AND l.period_id=%s AND l.journal_id IN %s ' + self.query_get_clause + ' ORDER BY l.'+ self.sort_selection + '' ,(tuple(move_state), period_id, tuple(journal_id) )) ids = map(lambda x: x[0], self.cr.fetchall()) return obj_mline.browse(self.cr, self.uid, ids) diff --git a/addons/account/report/account_journal.rml b/addons/account/report/account_journal.rml index 8ca005ea4ad..41261a12c1a 100644 --- a/addons/account/report/account_journal.rml +++ b/addons/account/report/account_journal.rml @@ -287,7 +287,7 @@ Entry No A/c No. Partner - Entry label + Move - Entry label Debit([[ company.currency_id.code]]) Credit([[ company.currency_id.code]]) Balance([[ company.currency_id.code]]) @@ -309,11 +309,11 @@ [[ line.ref ]] [[ line.account_id.code ]] [[ line.partner_id and line.partner_id.name ]] - [[ line.name ]] + [[ line.move_id.name ]] - [[ line.name ]] [[ formatLang(line.debit) ]] [[ company.currency_id.symbol ]] [[ formatLang(line.credit) ]] [[ company.currency_id.symbol ]] [[ formatLang(line.credit - line.debit) ]] [[ company.currency_id.symbol ]] - [[ line.currency_id and formatLang(line.amount_currency) or '' ]] [[ line.currency_id.code or '']] + [[ line.currency_id and formatLang(line.amount_currency) or '' ]] [[ line.currency_id.symbol or '']] diff --git a/addons/account/wizard/account_report_print_journal.py b/addons/account/wizard/account_report_print_journal.py index e9c5b0fbf81..096678860ac 100644 --- a/addons/account/wizard/account_report_print_journal.py +++ b/addons/account/wizard/account_report_print_journal.py @@ -30,16 +30,19 @@ class account_print_journal(osv.osv_memory): 'sort_selection': fields.selection([('date', 'Date'), ('ref', 'Reference Number'),], 'Entries Sorted By', required=True), + 'target_move': fields.selection([('all', 'All Entries'), + ('posted', 'All Posted Entries')], 'Target Moves', required=True) } _defaults = { 'sort_selection': 'date', + 'target_move': 'all' } def _print_report(self, cr, uid, ids, data, query_line, context=None): if context is None: context = {} data = self.pre_print_report(cr, uid, ids, data, query_line, context=context) - data['form'].update(self.read(cr, uid, ids, ['sort_selection'])[0]) + data['form'].update(self.read(cr, uid, ids, ['sort_selection','target_move'])[0]) return {'type': 'ir.actions.report.xml', 'report_name': 'account.journal.period.print', 'datas': data} account_print_journal() diff --git a/addons/account/wizard/account_report_print_journal_view.xml b/addons/account/wizard/account_report_print_journal_view.xml index 22cc1aca72a..2b4a597b87b 100644 --- a/addons/account/wizard/account_report_print_journal_view.xml +++ b/addons/account/wizard/account_report_print_journal_view.xml @@ -10,6 +10,7 @@ +