diff --git a/account_journal_report/README.rst b/account_journal_report/README.rst new file mode 100644 index 00000000..f843cdf4 --- /dev/null +++ b/account_journal_report/README.rst @@ -0,0 +1,67 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== +Journal Report +============== + +Adds the following report in PDF and XLSX format: + +* Journal Ledger. It groups the moves by their entries. + +Configuration +============= + +Users willing to access to this report should have proper Accounting & Finance rights: + +#. Go to *Settings / Users* and edit your user to add the corresponding access rights as follows. +#. In *Application / Accounting & Finance*, select *Accountant* or *Adviser* options. + +Usage +===== + +To use this module, you need to: + +#. Go to *Invoicing* or *Accounting* menu +#. Press 'Reporting > PDF Reports > Journal Ledger' +#. Press 'Print' to print in PDF or 'Export' to export in Excel. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/91/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted it +first, help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Joaquin Gutierrez +* Pedro M. Baeza +* RGB Consulting SL (http://www.rgbconsulting.com) +* Miquel Raïch + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_journal_report/__init__.py b/account_journal_report/__init__.py new file mode 100644 index 00000000..cae5318c --- /dev/null +++ b/account_journal_report/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa S.L. (http://www.tecnativa.com) +# Pedro M. Baeza +# Copyright 2017 RGB Consulting S.L. (http://www.rgbconsulting.com) +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import report +from . import wizard diff --git a/account_journal_report/__openerp__.py b/account_journal_report/__openerp__.py new file mode 100644 index 00000000..b70fddb3 --- /dev/null +++ b/account_journal_report/__openerp__.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa - Pedro M. Baeza +# Copyright 2017 RGB Consulting +# Copyright 2017 Eficent - Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': "Journal Report", + 'version': "9.0.1.0.0", + 'depends': [ + "account", + "report_xlsx", + ], + 'license': "AGPL-3", + 'author': "J. Gutierrez, " + "Tecnativa, " + "RGB Consulting, " + "Eficent, " + "Odoo Community Association (OCA)", + 'website': "http://github.com/OCA/account-financial-reporting", + 'category': "Accounting", + 'summary': "Journal Report", + 'data': [ + "wizard/wizard_print_journal_ledger_view.xml", + "report/reports.xml", + "views/templates.xml", + ], + "installable": True, +} diff --git a/account_journal_report/i18n/es.po b/account_journal_report/i18n/es.po new file mode 100644 index 00000000..7c970981 --- /dev/null +++ b/account_journal_report/i18n/es.po @@ -0,0 +1,259 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_journal_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-02 14:48+0200\n" +"PO-Revision-Date: 2017-05-02 14:48+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.7.1\n" +"Last-Translator: \n" +"Language: es\n" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:74 +#, python-format +msgid " to " +msgstr " a " + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "Account name" +msgstr "Nombre cuenta" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "Account" +msgstr "Cuenta" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "Description" +msgstr "Descripción" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:95 +#, python-format +msgid "Account" +msgstr "Cuenta" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:98 +#, python-format +msgid "Account name" +msgstr "Nombre cuenta" + +#. module: account_journal_report +#: selection:account.journal.entries.report,sort_selection:0 +msgid "By date" +msgstr "Por fecha" + +#. module: account_journal_report +#: selection:account.journal.entries.report,sort_selection:0 +msgid "By entry number" +msgstr "Por nº de entrada" + +#. module: account_journal_report +#: selection:account.journal.entries.report,sort_selection:0 +msgid "By reference number" +msgstr "Por referencia" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.account_journal_ledger_report_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_create_date +msgid "Created on" +msgstr "Creado el" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:107 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Credit" +msgstr "Haber" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:92 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Date" +msgstr "Fecha" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_date_end +msgid "Date end" +msgstr "Fecha final" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_date_start +msgid "Date start" +msgstr "Fecha inicial" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:104 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Debit" +msgstr "Debe" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:101 +#, python-format +msgid "Description" +msgstr "Descripción" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_display_name +#: model:ir.model.fields,field_description:account_journal_report.field_report_account_journal_report_journal_ledger_display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_sort_selection +msgid "Entries Sorted By" +msgstr "Entradas ordenadas por" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:89 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Entry" +msgstr "Entrada" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.account_journal_ledger_report_view +msgid "Export" +msgstr "Exportar" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "From" +msgstr "De" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:74 +#, python-format +msgid "From " +msgstr "De " + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_id +#: model:ir.model.fields,field_description:account_journal_report.field_report_account_journal_report_journal_ledger_id +msgid "ID" +msgstr "ID" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:79 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Journal" +msgstr "Diario" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:180 +#: model:ir.actions.report.xml,name:account_journal_report.account_journal_ledger_report +#: model:ir.actions.report.xml,name:account_journal_report.action_account_journal_ledger_xlsx +#: model:ir.ui.menu,name:account_journal_report.menu_journal_ledger_report +#, python-format +msgid "Journal Ledger" +msgstr "Libro Diario" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "Journal Ledger -" +msgstr "Libro Diario -" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_journal_ids +msgid "Journals" +msgstr "Diarios" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_landscape +msgid "Landscape mode" +msgstr "Modo apaisado" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report___last_update +#: model:ir.model.fields,field_description:account_journal_report.field_report_account_journal_report_journal_ledger___last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: account_journal_report +#: model:ir.model.fields,field_description:account_journal_report.field_account_journal_entries_report_write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: account_journal_report +#: code:addons/account_journal_report/wizard/wizard_print_journal_ledger.py:57 +#: code:addons/account_journal_report/wizard/wizard_print_journal_ledger.py:76 +#, python-format +msgid "No data available" +msgstr "No hay datos disponibles" + +#. module: account_journal_report +#: code:addons/account_journal_report/wizard/wizard_print_journal_ledger.py:58 +#: code:addons/account_journal_report/wizard/wizard_print_journal_ledger.py:77 +#, python-format +msgid "No records found for your selection!" +msgstr "No se han encontrado registros para su selección" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:82 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Partner" +msgstr "Empresa" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.account_journal_ledger_report_view +msgid "Print" +msgstr "Imprimir" + +#. module: account_journal_report +#: model:ir.actions.act_window,name:account_journal_report.wizard_account_journal_ledger_report_new +#: model:ir.model,name:account_journal_report.model_account_journal_entries_report +msgid "Print Journal Ledger" +msgstr "Imprimir Libro Diario" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.account_journal_ledger_report_view +msgid "Print journal ledger" +msgstr "Imprimir libro diario" + +#. module: account_journal_report +#: code:addons/account_journal_report/report/journal_ledger_report_xlsx.py:85 +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +#, python-format +msgid "Reference" +msgstr "Referencia" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.account_journal_ledger_report_view +msgid "or" +msgstr "o" + +#. module: account_journal_report +#: model:ir.ui.view,arch_db:account_journal_report.journal_ledger +msgid "to" +msgstr "a" diff --git a/account_journal_report/report/__init__.py b/account_journal_report/report/__init__.py new file mode 100644 index 00000000..5f29cc02 --- /dev/null +++ b/account_journal_report/report/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa S.L. (http://www.tecnativa.com) +# Pedro M. Baeza +# Copyright 2017 RGB Consulting S.L. (http://www.rgbconsulting.com) +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import journal_ledger_report +from . import journal_ledger_report_xlsx diff --git a/account_journal_report/report/journal_ledger_report.py b/account_journal_report/report/journal_ledger_report.py new file mode 100644 index 00000000..97eba2fa --- /dev/null +++ b/account_journal_report/report/journal_ledger_report.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa - Pedro M. Baeza +# Copyright 2017 RGB Consulting +# Copyright 2017 Eficent - Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models + + +class JournalLedger(models.AbstractModel): + _name = 'report.account_journal_report.journal_ledger' + + def _format_date_to_lang(self, str_date): + if 'lang' not in self._context: + return str_date + lang_code = self._context['lang'] + lang_id = self.env['res.lang']._lang_get(lang_code) + lang = self.env['res.lang'].browse(lang_id) + date = fields.Date.from_string(str_date) + return date.strftime(lang.date_format) + + @api.multi + def render_html(self, data): + account_move_obj = self.env['account.move'] + report_obj = self.env['report'] + + date_start = data.get('date_start') + date_end = data.get('date_end') + journal_ids = data.get('journal_ids', []) + + move_ids = account_move_obj.search( + [('date', '<=', date_end), + ('date', '>=', date_start), + ('journal_id', 'in', journal_ids), + ('state', '!=', 'draft')], + order=data.get('sort_selection', 'date') + ', id') + + report = report_obj._get_report_from_name( + 'account_journal_report.journal_ledger') + docargs = { + 'doc_model': report.model, + 'docs': move_ids, + 'date_start': self._format_date_to_lang( + date_start), + 'date_end': self._format_date_to_lang( + date_end), + } + return report_obj.render( + 'account_journal_report.journal_ledger', docargs) diff --git a/account_journal_report/report/journal_ledger_report_xlsx.py b/account_journal_report/report/journal_ledger_report_xlsx.py new file mode 100644 index 00000000..bc768ea8 --- /dev/null +++ b/account_journal_report/report/journal_ledger_report_xlsx.py @@ -0,0 +1,201 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 RGB Consulting S.L. (http://www.rgbconsulting.com) +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +try: + from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx +except ImportError: + ReportXlsx = object +from openerp.report import report_sxw +from openerp import _ + + +class JournalLedgerXlsx(ReportXlsx): + def __init__(self, name, table, rml=False, parser=False, header=True, + store=False): + super(ReportXlsx, self).__init__( + name, table, rml, parser, header, store) + + self.sheet = None + self.row_pos = None + + self.format_title = None + self.format_border_top = None + + def _define_formats(self, workbook): + """ Add cell formats to current workbook. + Available formats: + * format_title + * format_header + * format_header_right + * format_header_italic + * format_border_top + """ + self.format_title = workbook.add_format({ + 'bold': True, + 'align': 'center', + 'bg_color': '#46C646', + 'border': True + }) + self.format_header = workbook.add_format({ + 'bold': True, + 'bg_color': '#FFFFCC', + 'border': True + }) + self.format_header_right = workbook.add_format({ + 'bold': True, + 'bg_color': '#FFFFCC', + 'border': True, + 'align': 'right' + }) + self.format_header_italic = workbook.add_format({ + 'bold': True, + 'bg_color': '#FFFFCC', + 'border': True, + 'italic': True + }) + self.format_border_top = workbook.add_format({ + 'top': 1, + 'bg_color': '#eeeeee' + }) + + def _write_report_title(self, title): + self.sheet.merge_range( + self.row_pos, 0, self.row_pos, 6, title, self.format_title + ) + self.row_pos += 1 + + def _write_report_range(self, date1, date2): + self.sheet.merge_range( + self.row_pos, 0, self.row_pos, 1, + _('From ')+date1+_(' to ')+date2+_(':')) + self.row_pos += 1 + + def _set_headers(self): + # Journal + self.sheet.write_string(self.row_pos, 2, _('Journal'), + self.format_header) + # Partner + self.sheet.write_string(self.row_pos, 3, _('Partner'), + self.format_header) + # Reference + self.sheet.write_string(self.row_pos, 4, _('Reference'), + self.format_header) + self.row_pos += 1 + # Entry + self.sheet.write_string(self.row_pos, 0, _('Entry'), + self.format_header) + # Date + self.sheet.write_string(self.row_pos, 1, _('Date'), self.format_header) + + # Account + self.sheet.write_string(self.row_pos, 2, _('Account'), + self.format_header_italic) + # Account name + self.sheet.write_string(self.row_pos, 3, _('Account name'), + self.format_header_italic) + # Description + self.sheet.write_string(self.row_pos, 4, _('Description'), + self.format_header_italic) + # Debit + self.sheet.write_string(self.row_pos, 5, _('Debit'), + self.format_header_right) + # Credit + self.sheet.write_string(self.row_pos, 6, _('Credit'), + self.format_header_right) + self.sheet.freeze_panes(4, 0) + self.row_pos += 1 + + def _generate_report_content(self, report_data): + for move in report_data: + # Entry + self.sheet.write_string(self.row_pos, 0, move.name or '', + self.format_border_top) + self.sheet.set_column(0, 0, 18) + # Date + self.sheet.write_string(self.row_pos, 1, move.date or '', + self.format_border_top) + self.sheet.set_column(1, 1, 12) + # Journal + self.sheet.write_string(self.row_pos, 2, + move.journal_id.name or '', + self.format_border_top) + self.sheet.set_column(2, 2, 30) + # Partner + self.sheet.write_string(self.row_pos, 3, + move.partner_id.name or '', + self.format_border_top) + self.sheet.set_column(3, 3, 40) + # Reference + self.sheet.write_string(self.row_pos, 4, move.ref or '', + self.format_border_top) + self.sheet.set_column(4, 4, 40) + # Debit + self.sheet.write_number(self.row_pos, 5, move.amount or 0, + self.format_border_top) + self.sheet.set_column(5, 5, 12) + # Credit + self.sheet.write_number(self.row_pos, 6, move.amount or 0, + self.format_border_top) + self.sheet.set_column(6, 6, 12) + + self.row_pos += 1 + for line in move.line_ids: + # Account code + self.sheet.write_string(self.row_pos, 2, + line.account_id.code or '') + # Account name + self.sheet.write_string(self.row_pos, 3, + line.account_id.name or '') + # Line description + self.sheet.write_string(self.row_pos, 4, line.name or '') + # Debit + self.sheet.write_number(self.row_pos, 5, line.debit or 0) + # Credit + self.sheet.write_number(self.row_pos, 6, line.credit or 0) + self.row_pos += 1 + + def generate_xlsx_report(self, workbook, data, objects): + date_start = data.get('date_start') + date_end = data.get('date_end') + journal_ids = data.get('journal_ids', []) + + report_data = self.env['account.move'].search( + [('date', '<=', date_end), + ('date', '>=', date_start), + ('journal_id', 'in', journal_ids), + ('state', '!=', 'draft')], + order=data.get('sort_selection', 'date') + ', id') + + # Initial row + self.row_pos = 0 + + # Load formats to workbook + self._define_formats(workbook) + + # Set report name + report_name = _('Journal Ledger') + ' - ' + \ + self.env.user.company_id.name + self.sheet = workbook.add_worksheet(report_name[:31]) + if data.get('landscape'): + self.sheet.set_landscape() + self.sheet.fit_to_pages(1, 0) + self.sheet.set_zoom(80) + self._write_report_title(report_name) + self._write_report_range(date_start, date_end) + + # Set headers + self._set_headers() + + # Generate data + self._generate_report_content(report_data) + + +if ReportXlsx != object: + JournalLedgerXlsx( + 'report.account_journal_report.journal_ledger_xlsx', + 'account.journal', parser=report_sxw.rml_parse + ) diff --git a/account_journal_report/report/reports.xml b/account_journal_report/report/reports.xml new file mode 100644 index 00000000..f528e795 --- /dev/null +++ b/account_journal_report/report/reports.xml @@ -0,0 +1,40 @@ + + + + + + + Journal Ledger + account.journal + ir.actions.report.xml + account_journal_report.journal_ledger_xlsx + xlsx + + + + + Account Journal Ledger + + A4 + + 10 + 10 + 7 + 7 + 0 + 90 + + + + + + + diff --git a/account_journal_report/static/description/icon.png b/account_journal_report/static/description/icon.png new file mode 100644 index 00000000..272d0294 Binary files /dev/null and b/account_journal_report/static/description/icon.png differ diff --git a/account_journal_report/tests/__init__.py b/account_journal_report/tests/__init__.py new file mode 100644 index 00000000..1ace59a9 --- /dev/null +++ b/account_journal_report/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_account_journal_report diff --git a/account_journal_report/tests/test_account_journal_report.py b/account_journal_report/tests/test_account_journal_report.py new file mode 100644 index 00000000..c2b9dbb9 --- /dev/null +++ b/account_journal_report/tests/test_account_journal_report.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openerp import fields +from openerp.tests.common import SavepointCase + + +class TestAccountJournalReport(SavepointCase): + """ + Tests for Account Journal Report. + """ + def setUp(self): + super(TestAccountJournalReport, self).setUp() + + self.report_model = \ + self.env['report.account_journal_report.journal_ledger'] + self.wiz = self.env['account.journal.entries.report'] + self.report_name = 'account_journal_report.journal_ledger' + self.action_name = 'account_journal_report.' \ + 'account_journal_ledger_report' + self.report_xlsx_name = 'account_journal_report.journal_ledger_xlsx' + self.action_xlsx_name = 'account_journal_report.' \ + 'action_account_journal_ledger_xlsx' + self.report_title = 'Journal Ledger' + + self.today = fields.Date.today() + + self.account_type = self.env['account.account.type'].create({ + 'name': 'Test account type', + 'type': 'other', + }) + self.account = self.env['account.account'].create({ + 'name': 'Test account', + 'code': 'TEST', + 'user_type_id': self.account_type.id, + }) + self.journal = self.env['account.journal'].create({ + 'name': 'Test journal', + 'code': 'TEST', + 'type': 'general', + }) + self.move = self.env['account.move'].create({ + 'journal_id': self.journal.id, + 'date': fields.Date.today(), + 'line_ids': [ + (0, 0, { + 'name': 'Debit line', + 'account_id': self.account.id, + 'debit': 100, + }), + (0, 0, { + 'name': 'Credit line', + 'account_id': self.account.id, + 'credit': 100, + }), + ], + }) + self.move.post() + + def test_account_journal_report(self): + + wiz_id = self.wiz.create({ + 'journal_ids': [(6, 0, self.journal.ids)], + 'date_start': self.today, + 'date_end': self.today, + }) + report = wiz_id.print_report() + + self.assertDictContainsSubset( + { + 'type': 'ir.actions.report.xml', + 'report_name': self.report_name, + 'report_type': 'qweb-pdf', + }, + report, + 'There was an error and the PDF report was not generated.' + ) + + data = wiz_id.read()[0] + report = self.env.ref(self.action_name).\ + render_report( + wiz_id.ids, self.report_name, data + ) + self.assertGreaterEqual(len(report[0]), 1) + self.assertEqual(report[1], 'html') + + def test_account_journal_report_xlsx(self): + + wiz_id = self.wiz.create({ + 'journal_ids': [(6, 0, self.journal.ids)], + 'date_start': self.today, + 'date_end': self.today, + }) + report = wiz_id.print_report_xlsx() + + self.assertDictContainsSubset( + { + 'type': 'ir.actions.report.xml', + 'report_type': 'xlsx', + 'report_name': self.report_xlsx_name, + }, + report, + 'There was an error and the XLSX report was not generated.' + ) + + data = wiz_id.read()[0] + report_xlsx = self.env.ref(self.action_xlsx_name).\ + render_report( + wiz_id.ids, self.report_xlsx_name, data + ) + + self.assertGreaterEqual(len(report_xlsx[0]), 1) + self.assertEqual(report_xlsx[1], 'xlsx') diff --git a/account_journal_report/views/templates.xml b/account_journal_report/views/templates.xml new file mode 100644 index 00000000..6adb8aff --- /dev/null +++ b/account_journal_report/views/templates.xml @@ -0,0 +1,85 @@ + + + + + diff --git a/account_journal_report/wizard/__init__.py b/account_journal_report/wizard/__init__.py new file mode 100644 index 00000000..8d8781d8 --- /dev/null +++ b/account_journal_report/wizard/__init__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa S.L. (http://www.tecnativa.com) +# Pedro M. Baeza +# Copyright 2017 RGB Consulting S.L. (http://www.rgbconsulting.com) +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard_print_journal_ledger diff --git a/account_journal_report/wizard/wizard_print_journal_ledger.py b/account_journal_report/wizard/wizard_print_journal_ledger.py new file mode 100644 index 00000000..e850b289 --- /dev/null +++ b/account_journal_report/wizard/wizard_print_journal_ledger.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Copyright 2013 Joaquin Gutierrez (http://www.gutierrezweb.es) +# Copyright 2015 Tecnativa - Pedro M. Baeza +# Copyright 2017 RGB Consulting +# Copyright 2017 Eficent - Miquel Raich +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from datetime import date, timedelta +from openerp import api, fields, models, exceptions, _ + + +class AccountJournalLedgerReport(models.TransientModel): + _name = "account.journal.entries.report" + _description = "Print Journal Ledger" + + @api.model + def _default_journal_ids(self): + return self.env['account.journal'].search([]) + + journal_ids = fields.Many2many( + comodel_name='account.journal', + relation="account_journal_entries_report_journals_rel", + string='Journals', required=True, default=_default_journal_ids, + ) + date_start = fields.Date(required=True, + default=fields.Date.to_string( + date.today()-timedelta(days=90))) + date_end = fields.Date(required=True, + default=fields.Date.to_string(date.today())) + sort_selection = fields.Selection( + [('date', 'By date'), + ('name', 'By entry number'), + ('ref', 'By reference number')], + string='Entries Sorted By', required=True, default='name', + ) + landscape = fields.Boolean(string='Landscape mode', default=True) + + @api.multi + def _check_data(self): + if not self.journal_ids: + return False + journal_obj = self.env['account.journal'] + for journal in self.journal_ids: + ids_journal = journal_obj.search( + [('id', '=', journal.id)]) + if ids_journal: + return True + return False + + @api.multi + def print_report(self): + """Print report PDF""" + + # Check data + if not self._check_data(): + raise exceptions.Warning( + _('No data available'), + _('No records found for your selection!')) + + report_name = 'account_journal_report.journal_ledger' + + # Call report + data = self.read()[0] + return self.env['report'].with_context( + {'landscape': self.landscape}).get_action(self, + report_name=report_name, + data=data) + + @api.multi + def print_report_xlsx(self): + """Print report XLSX""" + + # Check data + if not self._check_data(): + raise exceptions.Warning( + _('No data available'), + _('No records found for your selection!')) + + # Call report + data = self.read()[0] + report_name = 'account_journal_report.journal_ledger_xlsx' + return { + 'type': 'ir.actions.report.xml', + 'report_name': report_name, + 'report_type': 'xlsx', + 'datas': data} diff --git a/account_journal_report/wizard/wizard_print_journal_ledger_view.xml b/account_journal_report/wizard/wizard_print_journal_ledger_view.xml new file mode 100644 index 00000000..9cb927d1 --- /dev/null +++ b/account_journal_report/wizard/wizard_print_journal_ledger_view.xml @@ -0,0 +1,51 @@ + + + + Print journal ledger + account.journal.entries.report + +
+ + + + + + + + + + + + + +
+ + + Print Journal Ledger + ir.actions.act_window + account.journal.entries.report + form + form + + new + + + +