diff --git a/base_report_auto_create_qweb/README.rst b/base_report_auto_create_qweb/README.rst new file mode 100644 index 000000000..a8864216e --- /dev/null +++ b/base_report_auto_create_qweb/README.rst @@ -0,0 +1,50 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Report qweb auto generation +=========================== + +When creating a report in Settings > Technical > Actions > Reports or +Settings > Technical > Reports > Reports it will create an empty Qweb template +and the required linking info so that the user does not need to know how to do +all the links. + +New duplication button added, it enables the possibility of duplicating a report +and assigning to the duplicated one a suffix. If the copy option provided by the +system is used this will add 'copy' as suffix. + +Be careful with this option as it can create many unnecessary Qweb views because +it duplicates all the related files to the report you are copying. + +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 smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ +* Oihane Crucelaegui +* Pedro M. Baeza +* Ana Juaristi +* Alex Comba + +Maintainer +---------- + +.. image:: https://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 http://odoo-community.org. diff --git a/base_report_auto_create_qweb/__init__.py b/base_report_auto_create_qweb/__init__.py new file mode 100644 index 000000000..3fc79a2d7 --- /dev/null +++ b/base_report_auto_create_qweb/__init__.py @@ -0,0 +1,7 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import models +from . import wizard diff --git a/base_report_auto_create_qweb/__openerp__.py b/base_report_auto_create_qweb/__openerp__.py new file mode 100644 index 000000000..92f73e2ae --- /dev/null +++ b/base_report_auto_create_qweb/__openerp__.py @@ -0,0 +1,42 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +{ + "name": "Report qweb auto generation", + "version": "1.0", + "depends": [ + "report", + ], + "author": "OdooMRP team, " + "AvanzOSC, " + "Serv. Tecnol. Avanzados - Pedro M. Baeza, " + "Odoo Community Association (OCA), ", + "website": "http://www.odoomrp.com", + 'license': 'AGPL-3', + "contributors": [ + "Oihane Crucelaegui ", + "Pedro M. Baeza ", + "Ana Juaristi ", + ], + "category": "Tools", + "data": [ + "wizard/report_duplicate_view.xml", + "views/report_xml_view.xml", + ], + "installable": True, +} diff --git a/base_report_auto_create_qweb/i18n/base_report_auto_create_qweb.pot b/base_report_auto_create_qweb/i18n/base_report_auto_create_qweb.pot new file mode 100644 index 000000000..c3069f396 --- /dev/null +++ b/base_report_auto_create_qweb/i18n/base_report_auto_create_qweb.pot @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_report_auto_create_qweb +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-03 10:58+0000\n" +"PO-Revision-Date: 2015-06-03 10:58+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Cancel" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,create_uid:0 +msgid "Created by" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,create_date:0 +msgid "Created on" +msgstr "" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Duplicate" +msgstr "" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml:base_report_auto_create_qweb.ir_actions_report_xml_form_view +msgid "Duplicate Report" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,id:0 +msgid "ID" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,write_uid:0 +msgid "Last Updated by" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,write_date:0 +msgid "Last Updated on" +msgstr "" + +#. module: base_report_auto_create_qweb +#: model:ir.actions.act_window,name:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_action +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Report duplication" +msgstr "" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,suffix:0 +msgid "Suffix" +msgstr "" + +#. module: base_report_auto_create_qweb +#: code:addons/base_report_auto_create_qweb/models/report_xml.py:18 +#: code:addons/base_report_auto_create_qweb/models/report_xml.py:52 +#, python-format +msgid "Template Name must contain at least a dot in it's name" +msgstr "" + +#. module: base_report_auto_create_qweb +#: help:ir.actions.report.xml.duplicate,suffix:0 +msgid "This suffix will be added to the report" +msgstr "" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "or" +msgstr "" + diff --git a/base_report_auto_create_qweb/i18n/es.po b/base_report_auto_create_qweb/i18n/es.po new file mode 100644 index 000000000..a9e8240aa --- /dev/null +++ b/base_report_auto_create_qweb/i18n/es.po @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_report_auto_create_qweb +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-03 11:06+0000\n" +"PO-Revision-Date: 2015-06-03 11:06+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,create_uid:0 +msgid "Created by" +msgstr "Creado por" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,create_date:0 +msgid "Created on" +msgstr "Creado en" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Duplicate" +msgstr "Duplicar" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml:base_report_auto_create_qweb.ir_actions_report_xml_form_view +msgid "Duplicate Report" +msgstr "Duplicar informe" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,id:0 +msgid "ID" +msgstr "ID" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,write_uid:0 +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,write_date:0 +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: base_report_auto_create_qweb +#: model:ir.actions.act_window,name:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_action +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "Report duplication" +msgstr "Duplicación del informe" + +#. module: base_report_auto_create_qweb +#: field:ir.actions.report.xml.duplicate,suffix:0 +msgid "Suffix" +msgstr "Súfijo" + +#. module: base_report_auto_create_qweb +#: code:addons/base_report_auto_create_qweb/models/report_xml.py:18 +#: code:addons/base_report_auto_create_qweb/models/report_xml.py:52 +#, python-format +msgid "Template Name must contain at least a dot in it's name" +msgstr "El nombre de plantilla debe contener al menos un punto en su nombre" + +#. module: base_report_auto_create_qweb +#: help:ir.actions.report.xml.duplicate,suffix:0 +msgid "This suffix will be added to the report" +msgstr "Este súfijo será añadido al informe" + +#. module: base_report_auto_create_qweb +#: view:ir.actions.report.xml.duplicate:base_report_auto_create_qweb.ir_actions_report_xml_duplicate_form_view +msgid "or" +msgstr "o" + diff --git a/base_report_auto_create_qweb/models/__init__.py b/base_report_auto_create_qweb/models/__init__.py new file mode 100644 index 000000000..40a047607 --- /dev/null +++ b/base_report_auto_create_qweb/models/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import report_xml diff --git a/base_report_auto_create_qweb/models/report_xml.py b/base_report_auto_create_qweb/models/report_xml.py new file mode 100644 index 000000000..6c719f34d --- /dev/null +++ b/base_report_auto_create_qweb/models/report_xml.py @@ -0,0 +1,99 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from openerp import models, api, exceptions, _ + + +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report.xml' + + def _prepare_qweb_view_data(self, qweb_name, arch): + return { + 'name': qweb_name, + 'mode': 'primary', + 'type': 'qweb', + 'arch': arch, + } + + def _prepare_model_data_data(self, qweb_name, module, qweb_view): + return { + 'module': module, + 'name': qweb_name, + 'res_id': qweb_view.id, + 'model': 'ir.ui.view', + } + + def _prepare_value_view_data(self, name, model): + return { + 'name': name, + 'model': model, + 'key2': 'client_print_multi', + 'value_unpickle': 'ir.actions.report.xml,%s' % self.id, + } + + def _create_qweb(self, name, qweb_name, module, model, arch): + qweb_view_data = self._prepare_qweb_view_data(qweb_name, arch) + qweb_view = self.env['ir.ui.view'].create(qweb_view_data) + model_data_data = self._prepare_model_data_data( + qweb_name, module, qweb_view) + self.env['ir.model.data'].create(model_data_data) + value_view_data = self._prepare_value_view_data( + name, model) + self.env['ir.values'].sudo().create(value_view_data) + + @api.model + def create(self, values): + if not self.env.context.get('enable_duplication', False): + return super(IrActionsReport, self).create(values) + if (values.get('report_type') in ['qweb-pdf', 'qweb-html'] and + values.get('report_name') and + values['report_name'].find('.') == -1): + raise exceptions.Warning( + _("Template Name must contain at least a dot in it's name")) + report_xml = super(IrActionsReport, self).create(values) + if values.get('report_type') in ['qweb-pdf', 'qweb-html']: + report_view_ids = self.env.context.get('report_views', False) + suffix = self.env.context.get('suffix', 'copy') + name = values['name'] + model = values['model'] + report = values['report_name'] + module = report.split('.')[0] + report_name = report.split('.')[1] + for report_view in self.env['ir.ui.view'].browse(report_view_ids): + origin_name = report_name.replace(('_%s' % suffix), '') + origin_module = module.replace(('_%s' % suffix), '') + new_report_name = '%s_%s' % (origin_name, suffix) + qweb_name = report_view.name.replace( + origin_name, new_report_name) + arch = report_view.arch.replace( + origin_name, new_report_name).replace(origin_module + '.', + module + '.') + report_xml._create_qweb( + name, qweb_name, module, model, arch) + if not report_view_ids: + arch = ('\n' + '\n' % report_name) + report_xml._create_qweb(name, report_name, module, model, arch) + return report_xml + + @api.one + def copy(self, default=None): + if not self.env.context.get('enable_duplication', False): + return super(IrActionsReport, self).copy(default=default) + if default is None: + default = {} + suffix = self.env.context.get('suffix', 'copy') + default['name'] = '%s (%s)' % (self.name, suffix) + module = '%s_%s' % ( + self.report_name.split('.')[0], suffix.lower()) + report = '%s_%s' % (self.report_name.split('.')[1], suffix.lower()) + default['report_name'] = '%s.%s' % (module, report) + report_views = self.env['ir.ui.view'].search([ + ('name', 'ilike', self.report_name.split('.')[1]), + ('type', '=', 'qweb')]) + return super(IrActionsReport, + self.with_context( + report_views=report_views.ids, + suffix=suffix.lower())).copy(default=default) diff --git a/base_report_auto_create_qweb/static/description/icon.png b/base_report_auto_create_qweb/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_report_auto_create_qweb/static/description/icon.png differ diff --git a/base_report_auto_create_qweb/views/report_xml_view.xml b/base_report_auto_create_qweb/views/report_xml_view.xml new file mode 100644 index 000000000..e558770af --- /dev/null +++ b/base_report_auto_create_qweb/views/report_xml_view.xml @@ -0,0 +1,19 @@ + + + + + ir.actions.report.xml.form + ir.actions.report.xml + + + + +
+
+
+
+
+
+
diff --git a/base_report_auto_create_qweb/wizard/__init__.py b/base_report_auto_create_qweb/wizard/__init__.py new file mode 100644 index 000000000..1d0ac90ff --- /dev/null +++ b/base_report_auto_create_qweb/wizard/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import report_duplicate diff --git a/base_report_auto_create_qweb/wizard/report_duplicate.py b/base_report_auto_create_qweb/wizard/report_duplicate.py new file mode 100644 index 000000000..b461f1f99 --- /dev/null +++ b/base_report_auto_create_qweb/wizard/report_duplicate.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from openerp import api, fields, models + + +class IrActionsReportDuplicate(models.TransientModel): + _name = 'ir.actions.report.xml.duplicate' + + suffix = fields.Char( + string='Suffix', help='This suffix will be added to the report') + + @api.one + def duplicate_report(self): + active_id = self.env.context.get('active_id') + model = self.env.context.get('active_model') + if model: + object = self.env[model].browse(active_id) + object.with_context( + suffix=self.suffix, enable_duplication=True).copy() + return {} diff --git a/base_report_auto_create_qweb/wizard/report_duplicate_view.xml b/base_report_auto_create_qweb/wizard/report_duplicate_view.xml new file mode 100644 index 000000000..38ce052f7 --- /dev/null +++ b/base_report_auto_create_qweb/wizard/report_duplicate_view.xml @@ -0,0 +1,33 @@ + + + + + ir.actions.report.xml.duplicate.form + ir.actions.report.xml.duplicate + +
+ + + +
+
+
+
+
+ + + Report duplication + ir.actions.report.xml.duplicate + form + form + + new + + +
+