Browse Source

[IMP] <base_report_auto_create_qweb> added button to fix #255

pull/260/head
oihane 9 years ago
parent
commit
2cc68c75ed
  1. 18
      base_report_auto_create_qweb/models/report_xml.py
  2. 8
      base_report_auto_create_qweb/views/report_xml_view.xml

18
base_report_auto_create_qweb/models/report_xml.py

@ -9,6 +9,12 @@ from openerp import models, api, exceptions, _
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report.xml'
def _format_template_name(self, text):
from unidecode import unidecode
text = unidecode(unicode(text))
text.lower()
return text.encode('iso-8859-1')
def _prepare_qweb_view_data(self, qweb_name, arch):
return {
'name': qweb_name,
@ -45,6 +51,8 @@ class IrActionsReport(models.Model):
@api.model
def create(self, values):
values['report_name'] = self._format_template_name(
values.get('report_name', ''))
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
@ -97,3 +105,13 @@ class IrActionsReport(models.Model):
self.with_context(
report_views=report_views.ids,
suffix=suffix.lower())).copy(default=default)
@api.multi
def button_create_qweb(self):
self.ensure_one()
module = self.report_name.split('.')[0]
report_name = self.report_name.split('.')[1]
arch = ('<?xml version="1.0"?>\n'
'<t t-name="%s">\n</t>' % report_name)
self._create_qweb(self.name, report_name, module, self.model, arch)
self.associated_view()

8
base_report_auto_create_qweb/views/report_xml_view.xml

@ -5,7 +5,7 @@
<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="inherit_id" ref="report.act_report_xml_view_inherit" />
<field name="arch" type="xml">
<xpath expr="//form/group" position="before">
<header>
@ -13,7 +13,13 @@
string="Duplicate Report" class="oe_highlight" type="action"/>
</header>
</xpath>
<button name="associated_view" position="after">
<button type="object" class="oe_link" name="button_create_qweb"
string="Create QWeb view"
attrs="{'invisible':[('report_type', 'not in', ['qweb-pdf', 'qweb-html'])]}" />
</button>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save