[FIX][report_xls] Protect import. (#64)
[FIX][report_xls] Protect import.
Even after merging 2bf93a1d49
, import still breaks when trying to use module's stuff at class definition time when module is not imported.
I move xsl types to a failure-safe scope.
pull/67/head
parent
f180c3cc66
commit
65223f4a16
|
@ -29,13 +29,29 @@ from types import CodeType
|
||||||
from openerp.report.report_sxw import report_sxw
|
from openerp.report.report_sxw import report_sxw
|
||||||
from openerp import pooler
|
from openerp import pooler
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
xls_types_default = {
|
||||||
|
'bool': False,
|
||||||
|
'date': None,
|
||||||
|
'text': '',
|
||||||
|
'number': 0,
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import xlwt
|
import xlwt
|
||||||
from xlwt.Style import default_style
|
from xlwt.Style import default_style
|
||||||
except ImportError:
|
|
||||||
|
xls_types = {
|
||||||
|
'bool': xlwt.Row.set_cell_boolean,
|
||||||
|
'date': xlwt.Row.set_cell_date,
|
||||||
|
'text': xlwt.Row.set_cell_text,
|
||||||
|
'number': xlwt.Row.set_cell_number,
|
||||||
|
}
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
_logger.debug("Cannot import xlwt. This module will not be functional.")
|
_logger.debug("Cannot import xlwt. This module will not be functional.")
|
||||||
|
xls_types = xls_types_default
|
||||||
|
|
||||||
|
|
||||||
class AttrDict(dict):
|
class AttrDict(dict):
|
||||||
|
@ -45,22 +61,7 @@ class AttrDict(dict):
|
||||||
|
|
||||||
|
|
||||||
class report_xls(report_sxw):
|
class report_xls(report_sxw):
|
||||||
|
|
||||||
xls_types = {
|
|
||||||
'bool': xlwt.Row.set_cell_boolean,
|
|
||||||
'date': xlwt.Row.set_cell_date,
|
|
||||||
'text': xlwt.Row.set_cell_text,
|
|
||||||
'number': xlwt.Row.set_cell_number,
|
|
||||||
}
|
|
||||||
xls_types_default = {
|
|
||||||
'bool': False,
|
|
||||||
'date': None,
|
|
||||||
'text': '',
|
|
||||||
'number': 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
# TO DO: move parameters infra to configurable data
|
# TO DO: move parameters infra to configurable data
|
||||||
|
|
||||||
# header/footer
|
# header/footer
|
||||||
hf_params = {
|
hf_params = {
|
||||||
'font_size': 8,
|
'font_size': 8,
|
||||||
|
|
Loading…
Reference in New Issue