← Back to team overview

banking-addons-team team mailing list archive

lp:~banking-addons-team/banking-addons/bank-statement-reconcile-fix-1082386 into lp:banking-addons/bank-statement-reconcile-61

 

Alexandre Fayolle @ camptocamp has proposed merging lp:~banking-addons-team/banking-addons/bank-statement-reconcile-fix-1082386 into lp:banking-addons/bank-statement-reconcile-61.

Requested reviews:
  Banking Addons Team (banking-addons-team)
Related bugs:
  Bug #1082386 in Banking Addons: "account_statement_base_import: hardcodeded datemode in xls file processing"
  https://bugs.launchpad.net/banking-addons/+bug/1082386

For more details, see:
https://code.launchpad.net/~banking-addons-team/banking-addons/bank-statement-reconcile-fix-1082386/+merge/135905

[FIX] account_statement_base_import: when importing from excel, use the date mode of the file, and not a hardcoded value

-- 
https://code.launchpad.net/~banking-addons-team/banking-addons/bank-statement-reconcile-fix-1082386/+merge/135905
Your team Banking Addons Team is requested to review the proposed merge of lp:~banking-addons-team/banking-addons/bank-statement-reconcile-fix-1082386 into lp:banking-addons/bank-statement-reconcile-61.
=== modified file 'account_statement_base_import/parser/file_parser.py'
--- account_statement_base_import/parser/file_parser.py	2012-09-26 12:51:06 +0000
+++ account_statement_base_import/parser/file_parser.py	2012-11-23 14:04:24 +0000
@@ -59,6 +59,9 @@
         self.keys_to_validate = keys_to_validate
         self.convertion_dict = convertion_dict
         self.fieldnames = header
+        self._datemode = 0 # used only for xls documents,
+                           # 0 means Windows mode (1900 based dates).
+                           # Set in _parse_xls, from the contents of the file
 
     def _custom_format(self, *args, **kwargs):
         """
@@ -132,6 +135,7 @@
         # We ensure that cursor is at beginig of file
         wb_file.seek(0)
         wb = xlrd.open_workbook(wb_file.name)
+        self._datemode = wb.datemode
         sheet = wb.sheet_by_index(0)
         header = sheet.row_values(0)
         res = []
@@ -166,7 +170,7 @@
         for line in result_set:
             for rule in conversion_rules:
                 if conversion_rules[rule] == datetime.datetime:
-                    t_tuple = xlrd.xldate_as_tuple(line[rule], 1)
+                    t_tuple = xlrd.xldate_as_tuple(line[rule], self._datemode)
                     line[rule] = datetime.datetime(*t_tuple)
                 else:
                     line[rule] = conversion_rules[rule](line[rule])


Follow ups