Skip to content

Commit

Permalink
[FIX][report_xls] Protect import. (#64)
Browse files Browse the repository at this point in the history
[FIX][report_xls] Protect import.

Even after merging 2bf93a1, 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.
  • Loading branch information
yajo authored and pedrobaeza committed Aug 13, 2016
1 parent f180c3c commit 65223f4
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions report_xls/report_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,29 @@
from openerp.report.report_sxw import report_sxw
from openerp import pooler
import logging

_logger = logging.getLogger(__name__)

xls_types_default = {
'bool': False,
'date': None,
'text': '',
'number': 0,
}

try:
import xlwt
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.")
xls_types = xls_types_default


class AttrDict(dict):
Expand All @@ -45,22 +61,7 @@ def __init__(self, *args, **kwargs):


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

# header/footer
hf_params = {
'font_size': 8,
Expand Down

4 comments on commit 65223f4

@open-net-sarl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza Since this was commited i get this error:
File "/home/odoo/git/Odoo/odoo/openerp/service/report.py", line 119, in _check_report
raise openerp.osv.orm.except_orm(exc.message, exc.traceback)
except_orm: (u"type object 'report_xls' has no attribute 'xls_types'", (<type 'exceptions.AttributeError'>, AttributeError("type object 'report_xls' has no attribute 'xls_types'",), <traceback object at 0x7fd2bea4fb48>))

Can you please fix this quickly.

@lasley
Copy link

@lasley lasley commented on 65223f4 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please submit an issue with this information instead of commenting on a commit

@pedrobaeza
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He already opened the issue, but it was solved before. He doesn't update the code.

@lasley
Copy link

@lasley lasley commented on 65223f4 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad, thanks @pedrobaeza - was just going through the morning emails & didn't see the corresponding issue 👍

Please sign in to comment.