Skip to content

Commit

Permalink
[IMP] <base_report_auto_create_qweb> Fixed reported problems
Browse files Browse the repository at this point in the history
* Warning raised when template name does not contain '.'
* Template name was not same as template ID
* Dependecies added to __openerp__.py file
  • Loading branch information
oihane authored and SimoRubi committed Mar 17, 2021
1 parent d61d1e2 commit b1dc126
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
7 changes: 6 additions & 1 deletion base_report_auto_create_qweb/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>",
Expand Down
14 changes: 10 additions & 4 deletions base_report_auto_create_qweb/models/report_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
##############################################################################

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):
from unidecode import unidecode
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')
Expand Down Expand Up @@ -53,13 +59,13 @@ def _create_qweb(self, name, qweb_name, module, model, arch):
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
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)
Expand Down Expand Up @@ -112,6 +118,6 @@ def button_create_qweb(self):
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)
'<t t-name="%s">\n</t>' % self.report_name)
self._create_qweb(self.name, report_name, module, self.model, arch)
self.associated_view()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 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):
Expand All @@ -24,8 +25,8 @@ def test_creation_html(self):
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')
self.assertEqual(view_num, 1, 'Only one view must be created.')

def test_creation_duplicate_pdf(self):
report_pdf = self.report_model.create({
Expand All @@ -38,8 +39,8 @@ def test_creation_duplicate_pdf(self):
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.')
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',
Expand All @@ -51,6 +52,15 @@ def test_creation_duplicate_pdf(self):
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.')
self.assertNotEqual(view_num, 0, 'There are not related views.')

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',
})
1 change: 0 additions & 1 deletion base_report_auto_create_qweb/views/report_xml_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
</button>
</field>
</record>

</data>
</openerp>

0 comments on commit b1dc126

Please sign in to comment.