banking-addons-team team mailing list archive
-
banking-addons-team team
-
Mailing list archive
-
Message #01489
[Merge] lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files into lp:banking-addons/bank-statement-reconcile-7.0
Florian da Costa has proposed merging lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files into lp:banking-addons/bank-statement-reconcile-7.0.
Requested reviews:
Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
For more details, see:
https://code.launchpad.net/~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files/+merge/205981
I noticed the module account_statement_base_import did not handle xlsx files and I believe these work the same way that the xls files.
So I would like the file_parser to handle also the xlsx files.
Basically, I just changed 2 lines in the __init__ function of the parser.
If the file is xlsx, I put xls in the ftype variable so the parser act as if it is a xls file.
I tried an xlsx import this way and it worked great.
I did it this way in order to do the less changes possible, but I am not sure this is the right way...
What do you think?
--
https://code.launchpad.net/~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files/+merge/205981
Your team Banking Addons Core Editors is subscribed to branch lp:banking-addons/bank-statement-reconcile-7.0.
=== modified file 'account_statement_base_import/parser/file_parser.py'
--- account_statement_base_import/parser/file_parser.py 2013-11-06 17:27:53 +0000
+++ account_statement_base_import/parser/file_parser.py 2014-02-12 15:02:04 +0000
@@ -35,24 +35,24 @@
class FileParser(BankStatementImportParser):
"""
- Generic abstract class for defining parser for .csv or .xls file format.
+ Generic abstract class for defining parser for .csv, .xls or .xlsx file format.
"""
def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, **kwargs):
"""
:param char: parse_name: The name of the parser
- :param char: ftype: extension of the file (could be csv or xls)
+ :param char: ftype: extension of the file (could be csv, xls or xlsx)
:param dict: extra_fields: extra fields to add to the conversion dict. In the format
{fieldname: fieldtype}
:param list: header : specify header fields if the csv file has no header
"""
super(FileParser, self).__init__(parse_name, **kwargs)
- if ftype in ('csv', 'xls'):
- self.ftype = ftype
+ if ftype in ('csv', 'xls' ,'xlsx'):
+ self.ftype = ftype[0:3]
else:
raise except_osv(_('User Error'),
- _('Invalid file type %s. Please use csv or xls') % ftype)
+ _('Invalid file type %s. Please use csv, xls or xlsx') % ftype)
self.conversion_dict = {
'ref': unicode,
'label': unicode,
@@ -81,7 +81,7 @@
def _parse(self, *args, **kwargs):
"""
- Launch the parsing through .csv or .xls depending on the
+ Launch the parsing through .csv, .xls or .xlsx depending on the
given ftype
"""
@@ -128,7 +128,7 @@
def _parse_xls(self):
"""
- :return: dict of dict from xls file (line/rows)
+ :return: dict of dict from xls/xlsx file (line/rows)
"""
wb_file = tempfile.NamedTemporaryFile()
wb_file.write(self.filebuffer)
@@ -180,7 +180,7 @@
def _from_xls(self, result_set, conversion_rules):
"""
Handle the converstion from the dict and handle date format from
- an .xls file.
+ an .csv, .xls or .xlsx file.
"""
for line in result_set:
for rule in conversion_rules:
Follow ups