From edbaa302c2c1c70bc579a371e61489e09a7646ee Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 3 Feb 2012 15:53:20 +0100 Subject: [PATCH] [IMP] account: improved print journal report + added a dedicated RML for sale/purchase journal printing. Based on the same parser, this new report additionaly print information about VAT. From an original idea and parts of code of Noviat. bzr revid: qdp-launchpad@openerp.com-20120203145320-og4k4p008qybdcfc --- addons/account/account_report.xml | 1 + addons/account/report/account_journal.py | 43 ++- addons/account/report/account_journal.rml | 233 ++++++------ .../report/account_journal_sale_purchase.rml | 346 ++++++++++++++++++ .../wizard/account_report_print_journal.py | 37 +- .../account_report_print_journal_view.xml | 30 +- 6 files changed, 569 insertions(+), 121 deletions(-) create mode 100644 addons/account/report/account_journal_sale_purchase.rml diff --git a/addons/account/account_report.xml b/addons/account/account_report.xml index 0288bbd61dd..78caf1c95b6 100644 --- a/addons/account/account_report.xml +++ b/addons/account/account_report.xml @@ -10,6 +10,7 @@ + \'draft\'', + (period_id, journal_id) + ) + ids = map(lambda x: x[0], self.cr.fetchall()) + tax_code_ids = [] + if ids: + self.cr.execute('select id from account_tax_code where id in %s order by code', (tuple(ids),)) + tax_code_ids = map(lambda x: x[0], self.cr.fetchall()) + tax_codes = self.pool.get('account.tax.code').browse(self.cr, self.uid, tax_code_ids) + return tax_codes + + def _sum_vat(self, period_id, journal_id, tax_code_id): + self.cr.execute('select sum(tax_amount) from account_move_line where ' \ + 'period_id=%s and journal_id=%s and tax_code_id=%s and state<>\'draft\'', + (period_id, journal_id, tax_code_id)) + return self.cr.fetchone()[0] or 0.0 + def _sum_debit(self, period_id=False, journal_id=False): if journal_id and isinstance(journal_id, int): journal_id = [journal_id] @@ -118,7 +156,7 @@ class journal_print(report_sxw.rml_parse, common_report_header): 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 + ', l.move_id',(tuple(move_state), period_id, tuple(journal_id) )) + 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 '+ self.sort_selection + ', l.move_id',(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) @@ -155,5 +193,6 @@ class journal_print(report_sxw.rml_parse, common_report_header): return 'Date' report_sxw.report_sxw('report.account.journal.period.print', 'account.journal.period', 'addons/account/report/account_journal.rml', parser=journal_print, header='internal') +report_sxw.report_sxw('report.account.journal.period.print.sale.purchase', 'account.journal.period', 'addons/account/report/account_journal_sale_purchase.rml', parser=journal_print, header='internal') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/report/account_journal.rml b/addons/account/report/account_journal.rml index 122b195c1ef..acc11acaa98 100644 --- a/addons/account/report/account_journal.rml +++ b/addons/account/report/account_journal.rml @@ -18,10 +18,7 @@ - - - - + @@ -119,11 +116,17 @@ - - - + - + + + + + + + + + @@ -173,101 +176,92 @@ [[ repeatIn(objects, 'o') ]] - + - - Journal - + Journal - - - - - - - [[ data['model']=='account.journal.period'and 'Company' or removeParentNode('para') ]] - [[ data['model']=='ir.ui.menu' and 'Chart of Accounts' or removeParentNode('para') ]] - Fiscal Year - Journal - Filters By - Entries Sorted By - Target Moves - - - [[ get_account(data) or '' ]] - [[ get_fiscalyear(data) or '' ]] - [[o.journal_id.name ]] - [[ data['form']['filter']=='filter_no' and get_filter(data) or removeParentNode('para') ]] - [[ data['form']['filter']=='filter_date' or removeParentNode('blockTable') ]] - - Start Date - End Date - - - [[ formatLang(get_start_date(data),date=True) ]] - [[ formatLang(get_end_date(data),date=True) ]] - - - [[ data['form']['filter']=='filter_period' or removeParentNode('blockTable') ]] - - Start Period - End Period - - - [[ get_start_period(data) or removeParentNode('para') ]] - [[ get_end_period(data) or removeParentNode('para') ]] - - - - [[ get_sortby(data) ]] - [[ get_target_move(data) ]] - - - - - [[ display_currency(data) == False or removeParentNode('blockTable') ]] + - Date - Ref - Move - Account - Partner - Label - Debit - Credit + [[ data['model']=='account.journal.period'and 'Company' or removeParentNode('para') ]] + [[ data['model']=='ir.ui.menu' and 'Chart of Accounts' or removeParentNode('para') ]] + Fiscal Year + Journal + Period + Entries Sorted By + Target Moves - - [[o.period_id.name ]] - [[ o.journal_id.code ]] - - - - - [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] - [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] - - [[lines(o.period_id.id, o.journal_id.id) or removeParentNode('story') ]] - [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]][[ formatLang(line.date,date=True) ]] - [[ strip_name(line.ref,20) ]] - [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] - [[ line.account_id.code ]] - [[ line.partner_id and strip_name(line.partner_id.name,17) ]] - [[ strip_name(line.name,27) ]] - [[ formatLang(line.debit, currency_obj=company.currency_id) ]] - [[ formatLang(line.credit, currency_obj=company.currency_id) ]] + [[ get_account(data) or '' ]] + [[ get_fiscalyear(data) or '' ]] + [[ o.journal_id.name ]] + [[ o.period_id.name ]] + [[ get_sortby(data) ]] + [[ get_target_move(data) ]] + + + + + + + [[lines(o.period_id.id, o.journal_id.id) or removeParentNode('story') ]][[ set_last_move_id(False)]] +
+ [[ display_currency(data) == False or removeParentNode('section') ]] + + + Move + Date + Account + Partner + Label + Debit + Credit + + +
+ [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]] + + + [[ not check_last_move_id(line.move_id.id) and removeParentNode('blockTable') ]] + + + + + [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] + [[ formatLang(line.date,date=True) ]] + [[ line.account_id.code ]] + [[ line.partner_id and strip_name(line.partner_id.name,23) ]] + [[ strip_name(line.name,35) ]] + [[ formatLang(line.debit, currency_obj=company.currency_id) ]] + [[ formatLang(line.credit, currency_obj=company.currency_id) ]] + + + [[ set_last_move_id(line.move_id.id) ]] +
+ + + + + + + Total: + [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + + +
- [[ display_currency(data) or removeParentNode('blockTable') ]] +
+ [[ display_currency(data) or removeParentNode('section') ]] + - Date - Ref Move + Date Account Partner Label @@ -275,30 +269,41 @@ Credit Currency - - [[o.period_id.name ]] - [[ o.journal_id.code ]] - - - - - [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] - [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] - - - - [[lines(o.period_id.id, o.journal_id.id) or removeParentNode('story') ]] - - [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]][[ formatLang(line.date,date=True) ]] - [[ strip_name(line.ref,20) ]] - [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] - [[ line.account_id.code ]] - [[ line.partner_id and strip_name(line.partner_id.name,15) ]] - [[ strip_name(line.name,17) ]] - [[ formatLang(line.debit, currency_obj=company.currency_id) ]] - [[ formatLang(line.credit, currency_obj=company.currency_id) ]] - [[ line.currency_id and formatLang(line.amount_currency, currency_obj=line.currency_id) or '' ]] - - + +
+ [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]] + + + [[ not check_last_move_id(line.move_id.id) and removeParentNode('blockTable') ]] + + + + + [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] + [[ formatLang(line.date,date=True) ]] + [[ line.account_id.code ]] + [[ line.partner_id and strip_name(line.partner_id.name,17) ]] + [[ strip_name(line.name,28) ]] + [[ formatLang(line.debit, currency_obj=company.currency_id) ]] + [[ formatLang(line.credit, currency_obj=company.currency_id) ]] + [[ line.currency_id and formatLang(line.amount_currency, currency_obj=line.currency_id) or '' ]] + + + [[ set_last_move_id(line.move_id.id) ]] +
+ + + + + + + Total: + [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + + + + +
diff --git a/addons/account/report/account_journal_sale_purchase.rml b/addons/account/report/account_journal_sale_purchase.rml new file mode 100644 index 00000000000..fc42bb0a08d --- /dev/null +++ b/addons/account/report/account_journal_sale_purchase.rml @@ -0,0 +1,346 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects, 'o') ]] + + + + Journal + + + + + + + + [[ data['model']=='account.journal.period'and 'Company' or removeParentNode('para') ]] + [[ data['model']=='ir.ui.menu' and 'Chart of Accounts' or removeParentNode('para') ]] + Fiscal Year + Journal + Period + Entries Sorted By + Target Moves + + + [[ get_account(data) or '' ]] + [[ get_fiscalyear(data) or '' ]] + [[ o.journal_id.name ]] + [[ o.period_id.name ]] + [[ get_sortby(data) ]] + [[ get_target_move(data) ]] + + + + + + + + + [[lines(o.period_id.id, o.journal_id.id) or removeParentNode('story') ]][[ set_last_move_id(False)]] +
+ [[ display_currency(data) == False or removeParentNode('section') ]] + + + Move + Date + Account + Partner + Label + VAT + + Debit + Credit + + +
+ [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]] + + + [[ not check_last_move_id(line.move_id.id) and removeParentNode('blockTable') ]] + + + + + [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] + [[ formatLang(line.date,date=True) ]] + [[ line.account_id.code ]] + [[ line.partner_id and strip_name(line.partner_id.name,17) ]] + [[ strip_name(line.name,25) ]] + [[ line.tax_code_id and (line.tax_code_id.code + ':') ]] + [[ line.tax_amount and formatLang(line.tax_amount, currency_obj=company.currency_id) ]] + [[ formatLang(line.debit, currency_obj=company.currency_id) ]] + [[ formatLang(line.credit, currency_obj=company.currency_id) ]] + + + [[ set_last_move_id(line.move_id.id) ]] +
+ + + + + + + + + Total: + [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + + +
+ +
+ [[ display_currency(data) or removeParentNode('section') ]] + + + Move + Date + Account + Partner + Label + VAT + + Debit + Credit + Currency + + +
+ [[ repeatIn(lines(o.period_id.id, o.journal_id.id), 'line') ]] + + + [[ not check_last_move_id(line.move_id.id) and removeParentNode('blockTable') ]] + + + + + [[ line.move_id.name <> '/' and line.move_id.name or ('*'+str(line.move_id.id)) ]] + [[ formatLang(line.date,date=True) ]] + [[ line.account_id.code ]] + [[ line.partner_id and strip_name(line.partner_id.name,17) ]] + [[ strip_name(line.name,17) ]] + [[ line.tax_code_id and (line.tax_code_id.code + ':') ]] + [[ line.tax_amount and formatLang(line.tax_amount, currency_obj=company.currency_id) ]] + [[ formatLang(line.debit, currency_obj=company.currency_id) ]] + [[ formatLang(line.credit, currency_obj=company.currency_id) ]] + [[ line.currency_id and formatLang(line.amount_currency, currency_obj=line.currency_id) or '' ]] + + + [[ set_last_move_id(line.move_id.id) ]] +
+ + + + + + + + + Total: + [[ formatLang(sum_debit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + [[ formatLang(sum_credit(o.period_id.id, o.journal_id.id), currency_obj=company.currency_id) ]] + + + + +
+ + + + + + + +
+ + + + + + VAT Declaration + + + + + [[ repeatIn(tax_codes(o.period_id.id,o.journal_id.id), 't') ]][[ t.code + ': ' ]] + [[ formatLang(sum_vat( o.period_id.id, o.journal_id.id, t.id)) ]] + + [[ t.name ]] + + +
+
+
diff --git a/addons/account/wizard/account_report_print_journal.py b/addons/account/wizard/account_report_print_journal.py index 1fe350349b6..0ffbde3fa9e 100644 --- a/addons/account/wizard/account_report_print_journal.py +++ b/addons/account/wizard/account_report_print_journal.py @@ -20,6 +20,7 @@ ############################################################################## from osv import osv, fields +from lxml import etree class account_print_journal(osv.osv_memory): _inherit = "account.common.journal.report" @@ -27,21 +28,49 @@ class account_print_journal(osv.osv_memory): _description = 'Account Print Journal' _columns = { - 'sort_selection': fields.selection([('date', 'Date'), - ('ref', 'Reference Number'),], + 'sort_selection': fields.selection([('l.date', 'Date'), + ('am.name', 'Journal Entry Number'),], 'Entries Sorted by', required=True), 'journal_ids': fields.many2many('account.journal', 'account_print_journal_journal_rel', 'account_id', 'journal_id', 'Journals', required=True), } + _defaults = { - 'sort_selection': 'date', + 'sort_selection': 'am.name', + 'filter': 'filter_period', + 'journal_ids': False, } + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + ''' + used to set the domain on 'journal_ids' field: we exclude or only propose the journals of type + sale/purchase (+refund) accordingly to the presence of the key 'sale_purchase_only' in the context. + ''' + if context is None: + context = {} + res = super(account_print_journal, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) + doc = etree.XML(res['arch']) + + if context.get('sale_purchase_only'): + domain ="[('type', 'in', ('sale','purchase','sale_refund','purchase_refund'))]" + else: + domain ="[('type', 'not in', ('sale','purchase','sale_refund','purchase_refund'))]" + nodes = doc.xpath("//field[@name='journal_ids']") + for node in nodes: + node.set('domain', domain) + res['arch'] = etree.tostring(doc) + return res + + def _print_report(self, cr, uid, ids, data, context=None): if context is None: context = {} data = self.pre_print_report(cr, uid, ids, data, context=context) data['form'].update(self.read(cr, uid, ids, ['sort_selection'], context=context)[0]) - return {'type': 'ir.actions.report.xml', 'report_name': 'account.journal.period.print', 'datas': data} + if context.get('sale_purchase_only'): + report_name = 'account.journal.period.print.sale.purchase' + else: + report_name = 'account.journal.period.print' + return {'type': 'ir.actions.report.xml', 'report_name': report_name, '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 4d2359c5a80..a462be91d9c 100644 --- a/addons/account/wizard/account_report_print_journal_view.xml +++ b/addons/account/wizard/account_report_print_journal_view.xml @@ -17,6 +17,16 @@ + + + + + + + + + + @@ -31,7 +41,6 @@ new - + + Print Sale/Purchase Journal + ir.actions.act_window + account.print.journal + form + form + new + {'sale_purchase_only':True} + + + + +