Merge pull request #260 from oihane/8.0-fix-auto_qweb
[IMP] <base_report_auto_create_qweb> added button to fix #255pull/269/merge
commit
52f9f3e9ec
|
@ -32,6 +32,7 @@ install:
|
|||
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
|
||||
- travis_install_nightly
|
||||
- pip install python-ldap
|
||||
- pip install unidecode
|
||||
- printf '[options]\n\nrunning_env = dev' > ${HOME}/.openerp_serverrc
|
||||
- ln -s server_environment_files_sample ./server_environment_files
|
||||
script:
|
||||
|
|
|
@ -22,12 +22,17 @@
|
|||
"depends": [
|
||||
"report",
|
||||
],
|
||||
"external_dependencies": {
|
||||
"python": [
|
||||
"unidecode",
|
||||
],
|
||||
},
|
||||
"author": "OdooMRP team, "
|
||||
"AvanzOSC, "
|
||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
||||
"Odoo Community Association (OCA), ",
|
||||
"website": "http://www.odoomrp.com",
|
||||
'license': 'AGPL-3',
|
||||
"license": "AGPL-3",
|
||||
"contributors": [
|
||||
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
|
||||
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
|
||||
|
|
|
@ -4,11 +4,23 @@
|
|||
##############################################################################
|
||||
|
||||
from openerp import models, api, exceptions, _
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = 'ir.actions.report.xml'
|
||||
|
||||
def _format_template_name(self, text):
|
||||
try:
|
||||
from unidecode import unidecode
|
||||
except ImportError:
|
||||
_logger.debug('Can not `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,17 +57,19 @@ class IrActionsReport(models.Model):
|
|||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
if not self.env.context.get('enable_duplication', False):
|
||||
return super(IrActionsReport, self).create(values)
|
||||
values['report_name'] = self._format_template_name(
|
||||
values.get('report_name', ''))
|
||||
if (values.get('report_type') in ['qweb-pdf', 'qweb-html'] and
|
||||
values.get('report_name') and
|
||||
values['report_name'].find('.') == -1):
|
||||
raise exceptions.Warning(
|
||||
_("Template Name must contain at least a dot in it's name"))
|
||||
if not self.env.context.get('enable_duplication', False):
|
||||
return super(IrActionsReport, self).create(values)
|
||||
report_xml = super(IrActionsReport, self).create(values)
|
||||
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')
|
||||
suffix = self.env.context.get('suffix') or 'copy'
|
||||
name = values['name']
|
||||
model = values['model']
|
||||
report = values['report_name']
|
||||
|
@ -84,7 +98,7 @@ class IrActionsReport(models.Model):
|
|||
return super(IrActionsReport, self).copy(default=default)
|
||||
if default is None:
|
||||
default = {}
|
||||
suffix = self.env.context.get('suffix', 'copy')
|
||||
suffix = self.env.context.get('suffix') or 'copy'
|
||||
default['name'] = '%s (%s)' % (self.name, suffix)
|
||||
module = '%s_%s' % (
|
||||
self.report_name.split('.')[0], suffix.lower())
|
||||
|
@ -97,3 +111,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>' % self.report_name)
|
||||
self._create_qweb(self.name, report_name, module, self.model, arch)
|
||||
self.associated_view()
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2015 Oihane Crucelaegui - AvanzOSC
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from . import test_base_report_auto_create_qweb
|
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2015 Oihane Crucelaegui - AvanzOSC
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
import openerp.tests.common as common
|
||||
from openerp import exceptions
|
||||
|
||||
|
||||
class TestBaseReportAutoQwebCreate(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBaseReportAutoQwebCreate, self).setUp()
|
||||
self.report_model = self.env['ir.actions.report.xml']
|
||||
self.duplicate_model = self.env['ir.actions.report.xml.duplicate']
|
||||
self.view_model = self.env['ir.ui.view']
|
||||
|
||||
def test_creation_html(self):
|
||||
report_html = self.report_model.create({
|
||||
'name': 'Test 1',
|
||||
'model': 'res.partner',
|
||||
'report_type': 'qweb-html',
|
||||
'report_name': 'test1.report_test',
|
||||
})
|
||||
report_html.button_create_qweb()
|
||||
view_num = self.view_model.search_count(
|
||||
[('name', 'ilike', report_html.report_name.split('.')[1]),
|
||||
('type', '=', 'qweb')])
|
||||
self.assertNotEqual(view_num, 0, 'There are not related views')
|
||||
self.assertEqual(view_num, 1, 'Only one view must be created.')
|
||||
|
||||
def test_creation_duplicate_pdf(self):
|
||||
report_pdf = self.report_model.create({
|
||||
'name': 'Test 2',
|
||||
'model': 'res.partner',
|
||||
'report_type': 'qweb-pdf',
|
||||
'report_name': 'test2.report_test',
|
||||
})
|
||||
report_pdf.button_create_qweb()
|
||||
view_num = self.view_model.search_count(
|
||||
[('name', 'ilike', report_pdf.report_name.split('.')[1]),
|
||||
('type', '=', 'qweb')])
|
||||
self.assertNotEqual(view_num, 0, 'There are not related views.')
|
||||
self.assertEqual(view_num, 1, 'One view must be created.')
|
||||
wizard = self.duplicate_model.with_context(
|
||||
active_id=report_pdf.id, model=report_pdf.model).create({
|
||||
'suffix': 'copytest',
|
||||
})
|
||||
wizard.duplicate_report()
|
||||
report_pdf_copies = self.report_model.search(
|
||||
[('report_name', 'ilike', 'test2_copytest.report_test_copytest')])
|
||||
for report_pdf_copy in report_pdf_copies:
|
||||
view_num2 = self.view_model.search_count(
|
||||
[('name', 'ilike', report_pdf_copy.report_name.split('.')[1]),
|
||||
('type', '=', 'qweb')])
|
||||
self.assertNotEqual(view_num2, 0, 'There are not related views.')
|
||||
self.assertEqual(view_num2, view_num,
|
||||
'Same view numbers must have been created.')
|
||||
|
||||
def test_wrong_template_name(self):
|
||||
with self.assertRaises(exceptions.Warning):
|
||||
self.report_model.create({
|
||||
'name': 'Test',
|
||||
'model': 'res.partner',
|
||||
'report_type': 'qweb-pdf',
|
||||
'report_name': 'report_test',
|
||||
})
|
|
@ -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,6 +13,11 @@
|
|||
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" colspan="2"
|
||||
attrs="{'invisible':[('report_type', 'not in', ['qweb-pdf', 'qweb-html'])]}" />
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue