Browse Source

[IMP] <base_report_auto_create_qweb> added test and some fixes

pull/260/head
oihane 9 years ago
parent
commit
495db6261a
  1. 4
      base_report_auto_create_qweb/models/report_xml.py
  2. 5
      base_report_auto_create_qweb/tests/__init__.py
  3. 56
      base_report_auto_create_qweb/tests/test_base_report_auto_create_qweb.py
  4. 2
      base_report_auto_create_qweb/views/report_xml_view.xml

4
base_report_auto_create_qweb/models/report_xml.py

@ -63,7 +63,7 @@ class IrActionsReport(models.Model):
report_xml = super(IrActionsReport, self).create(values) report_xml = super(IrActionsReport, self).create(values)
if values.get('report_type') in ['qweb-pdf', 'qweb-html']: if values.get('report_type') in ['qweb-pdf', 'qweb-html']:
report_view_ids = self.env.context.get('report_views', False) 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'] name = values['name']
model = values['model'] model = values['model']
report = values['report_name'] report = values['report_name']
@ -92,7 +92,7 @@ class IrActionsReport(models.Model):
return super(IrActionsReport, self).copy(default=default) return super(IrActionsReport, self).copy(default=default)
if default is None: if default is None:
default = {} default = {}
suffix = self.env.context.get('suffix', 'copy')
suffix = self.env.context.get('suffix') or 'copy'
default['name'] = '%s (%s)' % (self.name, suffix) default['name'] = '%s (%s)' % (self.name, suffix)
module = '%s_%s' % ( module = '%s_%s' % (
self.report_name.split('.')[0], suffix.lower()) self.report_name.split('.')[0], suffix.lower())

5
base_report_auto_create_qweb/tests/__init__.py

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

56
base_report_auto_create_qweb/tests/test_base_report_auto_create_qweb.py

@ -0,0 +1,56 @@
# -*- 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
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.assertEqual(view_num, 1, 'Only one view must be created.')
self.assertNotEqual(view_num, 0, 'There are not related views')
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.assertEqual(view_num, 1, 'One view must be created.')
self.assertNotEqual(view_num, 0, 'There are not related views.')
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.assertEqual(view_num2, view_num,
'Same view numbers must have been created.')
self.assertNotEqual(view_num, 0, 'There are not related views.')

2
base_report_auto_create_qweb/views/report_xml_view.xml

@ -15,7 +15,7 @@
</xpath> </xpath>
<button name="associated_view" position="after"> <button name="associated_view" position="after">
<button type="object" class="oe_link" name="button_create_qweb" <button type="object" class="oe_link" name="button_create_qweb"
string="Create QWeb view"
string="Create QWeb view" colspan="2"
attrs="{'invisible':[('report_type', 'not in', ['qweb-pdf', 'qweb-html'])]}" /> attrs="{'invisible':[('report_type', 'not in', ['qweb-pdf', 'qweb-html'])]}" />
</button> </button>
</field> </field>

Loading…
Cancel
Save