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