Browse Source

add unit test

14.0
Luc De Meyer 6 years ago
committed by Saran440
parent
commit
61adba8fc9
  1. 3
      report_xlsx_helper/tests/__init__.py
  2. 100
      report_xlsx_helper/tests/test_partner_report_xlsx.py
  3. 22
      report_xlsx_helper/tests/test_report_xlsx_helper.py

3
report_xlsx_helper/tests/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import test_partner_report_xlsx
from . import test_report_xlsx_helper

100
report_xlsx_helper/tests/test_partner_report_xlsx.py

@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.addons.report_xlsx_helper.report.abstract_report_xlsx \
import AbstractReportXlsx
from odoo.report import report_sxw
class TestPartnerReportXlsx(AbstractReportXlsx):
def _get_ws_params(self, wb, data, partners):
partner_template = {
'name': {
'header': {
'value': 'Name',
},
'data': {
'value': self._render("partner.name"),
},
'width': 20,
},
'number_of_contacts': {
'header': {
'value': '# Contacts',
},
'data': {
'value': self._render("len(partner.child_ids)"),
},
'width': 10,
},
'is_customer': {
'header': {
'value': 'Customer',
},
'data': {
'value': self._render("partner.customer"),
},
'width': 10,
},
'is_customer_formula': {
'header': {
'value': 'Customer Y/N ?',
},
'data': {
'type': 'formula',
'value': self._render("customer_formula"),
},
'width': 10,
},
}
ws_params = {
'ws_name': 'Partners',
'generate_ws_method': '_partner_report',
'title': 'Partners',
'wanted_list': [k for k in partner_template],
'col_specs': partner_template,
}
return [ws_params]
def _partner_report(self, workbook, ws, ws_params, data, partners):
ws.set_portrait()
ws.fit_to_pages(1, 0)
ws.set_header(self.xls_headers['standard'])
ws.set_footer(self.xls_footers['standard'])
self._set_column_width(ws, ws_params)
row_pos = 0
row_pos = self._write_ws_title(ws, row_pos, ws_params)
row_pos = self._write_line(
ws, row_pos, ws_params, col_specs_section='header',
default_format=self.format_theader_yellow_left)
ws.freeze_panes(row_pos, 0)
wl = ws_params['wanted_list']
for partner in partners:
is_customer_pos = 'is_customer' in wl and \
wl.index('is_customer')
is_customer_cell = self._rowcol_to_cell(
row_pos, is_customer_pos)
customer_formula = 'IF(%s=TRUE;"Y"; "N")' % is_customer_cell
row_pos = self._write_line(
ws, row_pos, ws_params, col_specs_section='data',
render_space={
'partner': partner,
'customer_formula': customer_formula,
},
default_format=self.format_tcell_left)
TestPartnerReportXlsx(
'report.test.partner.xlsx',
'res.partner',
parser=report_sxw.rml_parse)

22
report_xlsx_helper/tests/test_report_xlsx_helper.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestReportXlsxHelper(TransactionCase):
def setUp(self):
super(TestReportXlsxHelper, self).setUp()
ctx = {'xlsx_export': True}
self.report = self.env['ir.actions.report.xml'].with_context(ctx)
self.report_name = 'test.partner.xlsx'
p1 = self.env.ref('base.res_partner_1')
p2 = self.env.ref('base.res_partner_2')
self.partners = p1 + p2
def test_report_xlsx_helper(self):
report_xls = self.report.render_report(
self.partners.ids, self.report_name, {})
self.assertEqual(report_xls[1], 'xlsx')
Loading…
Cancel
Save