← Back to team overview

clearcorp team mailing list archive

[Merge] lp:~dr.clearcorp/openerp-costa-rica/6.1-parser_BCR into lp:openerp-costa-rica

 

Diana Rodríguez Martínez has proposed merging lp:~dr.clearcorp/openerp-costa-rica/6.1-parser_BCR into lp:openerp-costa-rica.

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

For more details, see:
https://code.launchpad.net/~dr.clearcorp/openerp-costa-rica/6.1-parser_BCR/+merge/139514

[FIX] Fix parser for the new format in the file of BCR
-- 
https://code.launchpad.net/~dr.clearcorp/openerp-costa-rica/6.1-parser_BCR/+merge/139514
Your team CLEARCORP development team is subscribed to branch lp:openerp-costa-rica.
=== modified file 'l10n_cr_account_banking_cr_bcr/bcr_parser.py'
--- l10n_cr_account_banking_cr_bcr/bcr_parser.py	2012-07-18 03:20:08 +0000
+++ l10n_cr_account_banking_cr_bcr/bcr_parser.py	2012-12-12 17:09:26 +0000
@@ -29,7 +29,31 @@
 from copy import copy
 
 class BCRParser( object ):
+    """
+    Para noviembre de 2012 se cambia el formato del archivo del BCR. Se cambia el encabezado del archivo
+    así como el final del mismo. Además en la parte de abajo cambia el formato y visualización de los
+    saldos finales. 
+    
+    El cambio más evidente es el formato de la cuenta de banco, pasa de 1-246447-0 a 001-0246447-0
+    Revisión # 1                                                       Revisión#2
+    Encabezado anterior:                                               Encabezado nuevo
+        BANCO DE COSTA RICA                                              BANCO DE COSTA RICA
+        Movimiento de Cuenta Corriente 1-246447-0 Colones                MOVIMIENTO DE LA CUENTA  CORRIENTE No. 001-0246447-0  COLONES
+        Dueño: COMPA IA INMOBILIARIA CENTROA                             DUENO: COMPA IA INMOBILIARIA CENTROAMERICANA CICCR S                            
+        Movimiento realizado el periodo del 01-10-2012 al 31-10-2012     MOVIMIENTO REALIZADO                           DEL 01-11-2012 AL 30-11-2012
+    
+    Final de archivo
+    Revisión # 1                                                        Revisión #2
+    TOTALES DEL MOVIMIENTO CONTABILIZADO                                TOTALES DEL MOVIMIENTO CONTABILIZADO 
+          Cantidad  -------Monto--------                                CANTIDAD    -------MONTO-------- 
+    Débitos       239       81,876,681.22                               DEBITOS       209        67,553,414.30                                                                                                                                
+    Créditos       27       92,636,599.01                               CREDITOS        8        66,086,326.53
 
+    Saldo Inicial            21,682,799.04                              -------- SALDOS --------                            
+    Saldo Final              33,992,829.43                              INICIAL             33,992,829.43
+                                                                        FINAL               32,525,741.66
+    Solicitado el 01/11/2012 20:03:34                                   SOLICITADO EL 01-12-2012 A LAS 15:36:15:17                                       
+    """
     def statement_record ( self, rec ):
         lines = []
         line_dict = {}
@@ -46,45 +70,75 @@
             'id': '',
         }
 
-        #file = open( filename, 'r' )
-        #line = file.readline()
         cad = ''
         list_split = rec.split('\r\n')
 
         for l in list_split:
-            # _transmission_number
-            if l.find('Movimiento realizado el periodo', 0, len('Movimiento realizado el periodo')) > -1:
+            
+            # _transmission_number -> FIRST REVISION
+            if (l.find('Movimiento realizado el periodo', 0, len('Movimiento realizado el periodo')) > -1):
                 line_dict['statementnr'] = self.extract_number(l)
-            #_account_number
+            # _transmission_number -> SECOND REVISION
+            elif (l.find('MOVIMIENTO REALIZADO', 0, len('MOVIMIENTO REALIZADO')) > -1):
+                line_dict['statementnr'] = self.extract_number(l)   
+                           
+            #_account_number -> FIRST REVISION
             if l.find('Movimiento de Cuenta Corriente', 0, len('Movimiento de Cuenta Corriente')) > -1:
-                line_dict['account_number'] = self.extract_number(l)
-                #cad = self.extract_currency_code_USD(l)
-                if l.find('D',0,len(l)) > -1:
+                line_dict['account_number'] = self.extract_number(l)                
+                if l.find('Dolares',0,len(l)) > -1:
                     line_dict['currencycode'] = 'USD'
                 else:
                     line_dict['currencycode'] = 'CRC'
-            # _transmission_number
-            if l.find('Solicitado el', 0, len('Solicitado el'))  > -1 :
-                line_dict['transref'] = self.extract_number(l)
-                line_dict['bookingdate'] = self.extract_number(l)               
-            #_opening_balance
+            #_account_number -> SECOND REVISION        
+            elif (l.find('MOVIMIENTO DE LA CUENTA  CORRIENTE No.', 0, len('MOVIMIENTO DE LA CUENTA  CORRIENTE No.')) > -1):
+                account_str = self.extract_number(l)   
+                #001-0246447-0
+                account_1 = account_str[2:3] #1
+                account_2 = account_str[4:]  #246447-0
+                account_complete = account_1+self.extract_number(account_2)#12464470
+                line_dict['account_number'] = self.extract_number(account_complete)
+                if l.find('DOLARES',0,len(l)) > -1:
+                    line_dict['currencycode'] = 'USD'
+                else:
+                    line_dict['currencycode'] = 'CRC'                      
+             
+            #FECHA Y HORA -> FIRST REVISION 
+            if (l.find('Solicitado el', 0, len('Solicitado el'))  > -1):
+                date =  hour = cad = ''
+                date = self.extract_date_regular_expresion(l)
+                if len(date) > 0:                   
+                    hour = self.extract_hour_regular_expresion(l)
+                cad = date + ' ' + hour                
+                line_dict['transref'] = cad
+                line_dict['bookingdate'] = cad
+            #FECHA Y HORA -> SECOND REVISION 
+            elif (l.find('SOLICITADO EL', 0, len('SOLICITADO EL'))  > -1):
+                date =  hour = cad = ''
+                date = self.extract_date_regular_expresion(l)
+                if len(date) > 0:                   
+                    hour = self.extract_hour_regular_expresion(l)
+                cad = date + ' ' + hour                
+                line_dict['transref'] = cad
+                line_dict['bookingdate'] = cad        
+                               
+            #_opening_balance -> FIRST REVISION
             if l.find('Saldo Inicial', 0, len('Saldo Inicial'))  > -1:
                 line_dict['startingbalance'] = self.extract_float(l)
-            #_closing_balance
-            if l.find('Saldo Final', 0, len('Saldo Final'))  > -1:
-                line_dict['endingbalance'] = self.extract_float(l)
-                    
-        amount_statement = float( line_dict['startingbalance'] ) + float( line_dict['endingbalance'] )
-        line_dict['ammount'] = amount_statement
-        
-        date_str = self.parse_date_stamenent(line_dict['bookingdate'])
-        name = date_str + ' - ' + line_dict['account_number']
-        line_dict['id'] = name
-
+            #_opening_balance -> SECOND REVISION   
+            elif l.find('INICIAL', 0, len('INICIAL'))  > -1:
+                line_dict['startingbalance'] = self.extract_float(l)
+                    
+            #_closing_balance -> FIRST REVISION
+            if l.find('FINAL', 0, len('FINAL'))  > -1:
+                line_dict['endingbalance'] = self.extract_float(l)
+            #_closing_balance -> SECOND REVISION    
+            elif l.find('Saldo Final', 0, len('Saldo Final'))  > -1:
+                line_dict['endingbalance'] = self.extract_float(l)
+                    
+        line_dict['ammount'] = float( line_dict['startingbalance'] ) + float( line_dict['endingbalance'] )
+        line_dict['id'] = line_dict['bookingdate'] + ' - ' + line_dict['account_number']
         self.line_dict = line_dict
-        pp = PrettyPrinter()
-        pp.pprint(line_dict)
-        
+      
         return line_dict
             
     def statement_lines ( self, rec ):
@@ -132,6 +186,13 @@
                     currencycode = 'CRC'
                 break
             
+            elif l.find('MOVIMIENTO DE LA CUENTA  CORRIENTE No.', 0, len('MOVIMIENTO DE LA CUENTA  CORRIENTE No.')) > -1:
+                if l.find('D',0,len(l)) > -1:
+                    currencycode = 'USD'
+                else:
+                    currencycode = 'CRC'
+                break
+            
         sub_list = list_split [start:end]
         for sub in sub_list:
             #03-05-12
@@ -171,27 +232,7 @@
             
             lines.append(copy(mapping))
                             
-        return lines 
-        
-    def parse_date_stamenent(self,datestring):
-        try:
-            day = datestring[0:2]
-            month = datestring[2:4]
-            year = datestring[4:8]
-            hour = datestring[8:10]
-            minute = datestring[10:12]
-            second = datestring[12:14]
-        except Exception:
-            day = datestring[2]
-            month = datestring[4]
-            year = datestring[4:8]
-            hour = datestring[8:10]
-            minute = datestring[10:12]
-            second = datestring[12:14]          
-                   
-        date = datetime(int(year),int(month),int(day),int(hour),int(minute),int(second))
-        date_string = date.strftime("%Y-%m-%d %H:%M:%S")
-        return date_string
+        return lines    
     
     def parse_stamenent_record( self, rec ):
 
@@ -216,25 +257,19 @@
         # Convert date fields
         needdate = set( ["bookingdate"] )
                 
-        for field in matchkeys & needdate:
+        for field in matchkeys & needdate:            
             datestring = matchdict[field]
+            date = self.extract_date_regular_expresion(datestring)
+            hour = self.extract_hour_regular_expresion(datestring)
+            
+            date_complete = date + ' ' + hour
             try:
-                day = datestring[0:2]
-                month = datestring[2:4]
-                year = datestring[4:8]
-                hour = datestring[8:10]
-                minute = datestring[10:12]
-                second = datestring[12:14]
-            except Exception:
-                day = datestring[2]
-                month = datestring[4]
-                year = datestring[4:8]
-                hour = datestring[8:10]
-                minute = datestring[10:12]
-                second = datestring[12:14]          
-                       
-            date = datetime(int(year),int(month),int(day),int(hour),int(minute),int(second))
-            matchdict[field] = date
+                #FORMAT DATE REVISION # 1
+                date_obj= datetime.strptime(date_complete, "%d/%m/%Y %H:%M:%S")
+            except:
+                #FORMAT DATE REVISION # 2
+                date_obj= datetime.strptime(date_complete, "%d-%m-%Y %H:%M:%S")
+            matchdict[field] = date_obj
         
         return matchdict
                     
@@ -252,8 +287,34 @@
         
         for character in result:
             cad = cad + character       
-        return cad   
-    
+        return cad
+    
+    def extract_date_regular_expresion(self, date):
+        cad = ''
+        result = []
+        date_string = ''
+        #re.findall('[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}',str)[0]+' '+re.findall('[0-9]{2}:[0-9]{2}:[0-9]{2}',str)[0]
+        #FORMAT DATE FIRST REVISION
+        result = re.findall('[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}', date)
+       
+        if len(result) == 0:
+            #FORMAT DATE SECOND REVISION
+            result = re.findall('[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}',date)      
+        
+        for character in result:
+            cad = cad + character       
+        return cad
+    
+    def extract_hour_regular_expresion(self, date):
+        cad = ''
+        result = []
+
+        result = re.findall('[0-9]{2}:[0-9]{2}:[0-9]{2}',date)             
+        
+        for character in result:
+            cad = cad + character       
+        return cad
+
     def extract_currency_code_USD(self, currency):
         cad = ''
         result = re.findall(r'[D.lares]',currency)


Follow ups