Browse Source

[IMP] <base_report_auto_create_qweb> Qweb creation hooks

pull/195/head
oihane 9 years ago
committed by Alex Comba
parent
commit
1022979822
  1. 2
      base_report_auto_create_qweb/README.rst
  2. 100
      base_report_auto_create_qweb/models/report_xml.py

2
base_report_auto_create_qweb/README.rst

@ -7,7 +7,7 @@ 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 the duplicated one a suffix. If the copy option provided by the
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

100
base_report_auto_create_qweb/models/report_xml.py

@ -9,6 +9,40 @@ 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'].create(value_view_data)
@api.model
def create(self, values):
if (values.get('report_type') in ['qweb-pdf', 'qweb-html'] and
@ -20,61 +54,23 @@ class IrActionsReport(models.Model):
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')
report_name = values['report_name']
module = report_name.split('.')[0]
name = report_name.split('.')[1]
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 = name.replace(('_%s' % suffix), '')
origin_name = report_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)
qweb_name = report_view.name.replace(
origin_name, new_report_name)
arch = report_view.arch.replace(origin_name, new_report_name)
report_xml._create_qweb(
name, qweb_name, module, model, arch)
if not report_view_ids:
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)
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

Loading…
Cancel
Save