[IMP] <base_report_auto_create_qweb> Duplication of report added

pull/195/head
oihane 2015-06-02 15:12:15 +02:00 committed by Alex Comba
parent dd5e769e89
commit ee7eb90b04
8 changed files with 164 additions and 26 deletions

View File

@ -6,9 +6,13 @@ 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 and the required linking info so that the user does not need to know how to do
all the links. all the links.
Known issues / Roadmap New duplication button added, it enables the possibility of duplicating a report
====================== and assigning the duplicated one a suffix. If the copy option provided by the
* When copying, duplicate all the required objects 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.
Credits Credits
======= =======

View File

@ -4,3 +4,4 @@
############################################################################## ##############################################################################
from . import models from . import models
from . import wizard

View File

@ -34,6 +34,9 @@
], ],
"category": "Tools", "category": "Tools",
"summary": "", "summary": "",
"data": [], "data": [
"wizard/report_duplicate_view.xml",
"views/report_xml_view.xml",
],
"installable": True, "installable": True,
} }

View File

@ -18,26 +18,76 @@ class IrActionsReport(models.Model):
_("Template Name must contain at least a dot in it's name")) _("Template Name must contain at least a dot in it's name"))
report_xml = super(IrActionsReport, self).create(values) report_xml = super(IrActionsReport, self).create(values)
if values.get('report_type') in ['qweb-pdf', 'qweb-html']: if values.get('report_type') in ['qweb-pdf', 'qweb-html']:
qweb_view_data = { report_views = self.env.context.get('report_views')
'name': values['report_name'].split('.')[1], suffix = self.env.context.get('suffix', 'copy')
'mode': 'primary', report_name = values['report_name']
'type': 'qweb', module = report_name.split('.')[0]
'arch': '<?xml version="1.0"?>\n' name = report_name.split('.')[1]
'<t t-name="%s">\n</t>' % values['report_name'], for report_view in report_views:
} origin_name = name.replace(('_%s' % suffix), '')
qweb_view = self.env['ir.ui.view'].create(qweb_view_data) new_report_name = '%s_%s' % (origin_name, suffix)
model_data_data = { qweb_view_data = {
'module': values['report_name'].split('.')[0], 'name': report_view.name.replace(
'name': values['report_name'].split('.')[1], origin_name, new_report_name),
'res_id': qweb_view.id, 'mode': 'primary',
'model': 'ir.ui.view', 'type': 'qweb',
} 'arch': report_view.arch.replace(
self.env['ir.model.data'].create(model_data_data) origin_name, new_report_name),
value_view_data = { }
'name': values['name'], qweb_view = self.env['ir.ui.view'].create(qweb_view_data)
'model': values['model'], model_data_data = {
'key2': 'client_print_multi', 'module': module,
'value_unpickle': 'ir.actions.report.xml,%s' % report_xml.id, 'name': report_view.name.replace(
} origin_name, new_report_name),
self.env['ir.values'].create(value_view_data) 'res_id': qweb_view.id,
'model': 'ir.ui.view',
}
self.env['ir.model.data'].create(model_data_data)
value_view_data = {
'name': values['name'],
'model': values['model'],
'key2': 'client_print_multi',
'value_unpickle': ('ir.actions.report.xml,%s' %
report_xml.id),
}
self.env['ir.values'].create(value_view_data)
if not report_views:
qweb_view_data = {
'name': name,
'mode': 'primary',
'type': 'qweb',
'arch': '<?xml version="1.0"?>\n'
'<t t-name="%s">\n</t>' % report_name,
}
qweb_view = self.env['ir.ui.view'].create(qweb_view_data)
model_data_data = {
'module': module,
'name': name,
'res_id': qweb_view.id,
'model': 'ir.ui.view',
}
self.env['ir.model.data'].create(model_data_data)
value_view_data = {
'name': values['name'],
'model': values['model'],
'key2': 'client_print_multi',
'value_unpickle': (
'ir.actions.report.xml,%s' % report_xml.id),
}
self.env['ir.values'].create(value_view_data)
return report_xml return report_xml
@api.one
def copy(self, default=None):
if default is None:
default = {}
suffix = self.env.context.get('suffix', 'copy')
default['name'] = '%s (%s)' % (self.name, suffix)
default['report_name'] = '%s_%s' % (self.report_name, suffix.lower())
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,
suffix=suffix.lower())).copy(default=default)

View File

@ -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>

View File

@ -0,0 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from . import report_duplicate

View File

@ -0,0 +1,22 @@
# -*- 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).copy()
return {}

View File

@ -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>