Merge lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files into lp:banking-addons/bank-statement-reconcile-70

Proposed by Florian da Costa
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 119
Merged at revision: 132
Proposed branch: lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 60 lines (+8/-8)
1 file modified
account_statement_base_import/parser/file_parser.py (+8/-8)
To merge this branch: bzr merge lp:~florian-dacosta/banking-addons/bank-statement-reconcile-7.0_base_import_handle_xlsx_files
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
Frederic Clementi - Camptocamp functional Approve
Joël Grand-Guillaume @ camptocamp Pending
Review via email: mp+205981@code.launchpad.net

Description of the change

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?

To post a comment you must log in.
Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

Make sens :)

review: Approve (functional)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_base_import/parser/file_parser.py'
2--- account_statement_base_import/parser/file_parser.py 2013-11-06 17:27:53 +0000
3+++ account_statement_base_import/parser/file_parser.py 2014-02-12 15:02:04 +0000
4@@ -35,24 +35,24 @@
5
6 class FileParser(BankStatementImportParser):
7 """
8- Generic abstract class for defining parser for .csv or .xls file format.
9+ Generic abstract class for defining parser for .csv, .xls or .xlsx file format.
10 """
11
12 def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, **kwargs):
13 """
14 :param char: parse_name: The name of the parser
15- :param char: ftype: extension of the file (could be csv or xls)
16+ :param char: ftype: extension of the file (could be csv, xls or xlsx)
17 :param dict: extra_fields: extra fields to add to the conversion dict. In the format
18 {fieldname: fieldtype}
19 :param list: header : specify header fields if the csv file has no header
20 """
21
22 super(FileParser, self).__init__(parse_name, **kwargs)
23- if ftype in ('csv', 'xls'):
24- self.ftype = ftype
25+ if ftype in ('csv', 'xls' ,'xlsx'):
26+ self.ftype = ftype[0:3]
27 else:
28 raise except_osv(_('User Error'),
29- _('Invalid file type %s. Please use csv or xls') % ftype)
30+ _('Invalid file type %s. Please use csv, xls or xlsx') % ftype)
31 self.conversion_dict = {
32 'ref': unicode,
33 'label': unicode,
34@@ -81,7 +81,7 @@
35
36 def _parse(self, *args, **kwargs):
37 """
38- Launch the parsing through .csv or .xls depending on the
39+ Launch the parsing through .csv, .xls or .xlsx depending on the
40 given ftype
41 """
42
43@@ -128,7 +128,7 @@
44
45 def _parse_xls(self):
46 """
47- :return: dict of dict from xls file (line/rows)
48+ :return: dict of dict from xls/xlsx file (line/rows)
49 """
50 wb_file = tempfile.NamedTemporaryFile()
51 wb_file.write(self.filebuffer)
52@@ -180,7 +180,7 @@
53 def _from_xls(self, result_set, conversion_rules):
54 """
55 Handle the converstion from the dict and handle date format from
56- an .xls file.
57+ an .csv, .xls or .xlsx file.
58 """
59 for line in result_set:
60 for rule in conversion_rules:

Subscribers

People subscribed via source and target branches