Browse Source
Merge pull request #195 from tafaRU/8.0-base_report_auto_create_qweb-add
Merge pull request #195 from tafaRU/8.0-base_report_auto_create_qweb-add
[8.0] Add module 'base_report_auto_create_qweb'pull/251/head
12 changed files with 455 additions and 0 deletions
-
50base_report_auto_create_qweb/README.rst
-
7base_report_auto_create_qweb/__init__.py
-
42base_report_auto_create_qweb/__openerp__.py
-
85base_report_auto_create_qweb/i18n/base_report_auto_create_qweb.pot
-
85base_report_auto_create_qweb/i18n/es.po
-
6base_report_auto_create_qweb/models/__init__.py
-
99base_report_auto_create_qweb/models/report_xml.py
-
BINbase_report_auto_create_qweb/static/description/icon.png
-
19base_report_auto_create_qweb/views/report_xml_view.xml
-
6base_report_auto_create_qweb/wizard/__init__.py
-
23base_report_auto_create_qweb/wizard/report_duplicate.py
-
33base_report_auto_create_qweb/wizard/report_duplicate_view.xml
@ -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 <https://github.com/OCA/server-tools/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 <https://github.com/OCA/server-tools/issues/new?body=module:%20base_report_auto_create_qweb%0Aversion:%20{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es> |
||||
|
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> |
||||
|
* Ana Juaristi <anajuaristi@avanzosc.es> |
||||
|
* Alex Comba <alex.comba@agilebg.com> |
||||
|
|
||||
|
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. |
@ -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 |
@ -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 <oihanecrucelaegi@avanzosc.es>", |
||||
|
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>", |
||||
|
"Ana Juaristi <anajuaristi@avanzosc.es>", |
||||
|
], |
||||
|
"category": "Tools", |
||||
|
"data": [ |
||||
|
"wizard/report_duplicate_view.xml", |
||||
|
"views/report_xml_view.xml", |
||||
|
], |
||||
|
"installable": True, |
||||
|
} |
@ -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 "" |
||||
|
|
@ -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" |
||||
|
|
@ -0,0 +1,6 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# For copyright and license notices, see __openerp__.py file in root directory |
||||
|
############################################################################## |
||||
|
|
||||
|
from . import report_xml |
@ -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 = ('<?xml version="1.0"?>\n' |
||||
|
'<t t-name="%s">\n</t>' % 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) |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,19 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record model="ir.ui.view" id="ir_actions_report_xml_form_view"> |
||||
|
<field name="name">ir.actions.report.xml.form</field> |
||||
|
<field name="model">ir.actions.report.xml</field> |
||||
|
<field name="priority" eval="5" /> |
||||
|
<field name="inherit_id" ref="base.act_report_xml_view" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//form/group" position="before"> |
||||
|
<header> |
||||
|
<button name="%(ir_actions_report_xml_duplicate_action)d" |
||||
|
string="Duplicate Report" class="oe_highlight" type="action"/> |
||||
|
</header> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,6 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# For copyright and license notices, see __openerp__.py file in root directory |
||||
|
############################################################################## |
||||
|
|
||||
|
from . import report_duplicate |
@ -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 {} |
@ -0,0 +1,33 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record model="ir.ui.view" id="ir_actions_report_xml_duplicate_form_view"> |
||||
|
<field name="name">ir.actions.report.xml.duplicate.form</field> |
||||
|
<field name="model">ir.actions.report.xml.duplicate</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Report duplication"> |
||||
|
<group> |
||||
|
<field name="suffix" /> |
||||
|
</group> |
||||
|
<footer> |
||||
|
<button class="oe_highlight" name="duplicate_report" |
||||
|
string="Duplicate" type="object" /> |
||||
|
or |
||||
|
<button class="oe_link" special="cancel" |
||||
|
string="Cancel" /> |
||||
|
</footer> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record model="ir.actions.act_window" id="ir_actions_report_xml_duplicate_action"> |
||||
|
<field name="name">Report duplication</field> |
||||
|
<field name="res_model">ir.actions.report.xml.duplicate</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">form</field> |
||||
|
<field name="view_id" ref="ir_actions_report_xml_duplicate_form_view" /> |
||||
|
<field name="target">new</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue