Browse Source

[IMP] <base_report_auto_create_qweb> Duplication of report added

pull/195/head
oihane 10 years ago
committed by Alex Comba
parent
commit
ee7eb90b04
  1. 10
      base_report_auto_create_qweb/README.rst
  2. 1
      base_report_auto_create_qweb/__init__.py
  3. 5
      base_report_auto_create_qweb/__openerp__.py
  4. 94
      base_report_auto_create_qweb/models/report_xml.py
  5. 19
      base_report_auto_create_qweb/views/report_xml_view.xml
  6. 6
      base_report_auto_create_qweb/wizard/__init__.py
  7. 22
      base_report_auto_create_qweb/wizard/report_duplicate.py
  8. 33
      base_report_auto_create_qweb/wizard/report_duplicate_view.xml

10
base_report_auto_create_qweb/README.rst

@ -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
all the links.
Known issues / Roadmap
======================
* When copying, duplicate all the required objects
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
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
=======

1
base_report_auto_create_qweb/__init__.py

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

5
base_report_auto_create_qweb/__openerp__.py

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

94
base_report_auto_create_qweb/models/report_xml.py

@ -18,26 +18,76 @@ class IrActionsReport(models.Model):
_("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']:
qweb_view_data = {
'name': values['report_name'].split('.')[1],
'mode': 'primary',
'type': 'qweb',
'arch': '<?xml version="1.0"?>\n'
'<t t-name="%s">\n</t>' % values['report_name'],
}
qweb_view = self.env['ir.ui.view'].create(qweb_view_data)
model_data_data = {
'module': values['report_name'].split('.')[0],
'name': values['report_name'].split('.')[1],
'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)
report_views = self.env.context.get('report_views')
suffix = self.env.context.get('suffix', 'copy')
report_name = values['report_name']
module = report_name.split('.')[0]
name = report_name.split('.')[1]
for report_view in report_views:
origin_name = name.replace(('_%s' % suffix), '')
new_report_name = '%s_%s' % (origin_name, suffix)
qweb_view_data = {
'name': report_view.name.replace(
origin_name, new_report_name),
'mode': 'primary',
'type': 'qweb',
'arch': report_view.arch.replace(
origin_name, new_report_name),
}
qweb_view = self.env['ir.ui.view'].create(qweb_view_data)
model_data_data = {
'module': module,
'name': report_view.name.replace(
origin_name, new_report_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)
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
@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)

19
base_report_auto_create_qweb/views/report_xml_view.xml

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

6
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

22
base_report_auto_create_qweb/wizard/report_duplicate.py

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

33
base_report_auto_create_qweb/wizard/report_duplicate_view.xml

@ -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>
Loading…
Cancel
Save