← Back to team overview

clearcorp team mailing list archive

lp:~dr.clearcorp/openerp-costa-rica/6.1-l10n_cr_bank_extract_fix into lp:openerp-costa-rica/6.1

 

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

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

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

[ADD] Add account_parser_type module as dependency of bac, bcr, bncr, davivienda and lafise bank
[FIX] Fix l10n_cr_account_banking_cr_lafise format 
-- 
https://code.launchpad.net/~dr.clearcorp/openerp-costa-rica/6.1-l10n_cr_bank_extract_fix/+merge/162553
Your team CLEARCORP development team is subscribed to branch lp:openerp-costa-rica/6.1.
=== modified file 'l10n_cr_account_banking_cr_bac/__openerp__.py'
--- l10n_cr_account_banking_cr_bac/__openerp__.py	2012-07-12 00:37:04 +0000
+++ l10n_cr_account_banking_cr_bac/__openerp__.py	2013-05-06 01:43:13 +0000
@@ -27,7 +27,7 @@
     'author': 'CLEARCORP S.A.',
     'website': 'http://www.clearcorp.co.cr',
     'category': 'Account Banking',
-    'depends': ['account_banking'],
+    'depends': ['account_banking','account_parser_type',],
     'init_xml': [],
     'update_xml': [
     ],

=== modified file 'l10n_cr_account_banking_cr_bcr/__openerp__.py'
--- l10n_cr_account_banking_cr_bcr/__openerp__.py	2013-03-14 15:57:05 +0000
+++ l10n_cr_account_banking_cr_bcr/__openerp__.py	2013-05-06 01:43:13 +0000
@@ -27,7 +27,7 @@
     'author': 'CLEARCORP S.A.',
     'website': 'http://www.clearcorp.co.cr',
     'category': 'Account Banking',
-    'depends': ['account_banking'],
+    'depends': ['account_banking','account_parser_type'],
     'init_xml': [],
     'update_xml': [],
     'demo_xml': [],

=== modified file 'l10n_cr_account_banking_cr_bncr/__openerp__.py'
--- l10n_cr_account_banking_cr_bncr/__openerp__.py	2013-03-14 15:57:05 +0000
+++ l10n_cr_account_banking_cr_bncr/__openerp__.py	2013-05-06 01:43:13 +0000
@@ -27,7 +27,7 @@
     'author': 'CLEARCORP S.A.',
     'website': 'http://www.clearcorp.co.cr',
     'category': 'Account Banking',
-    'depends': ['account_banking'],
+    'depends': ['account_banking','account_parser_type',],
     'init_xml': [],
     'update_xml': [],
     'demo_xml': [],

=== modified file 'l10n_cr_account_banking_cr_davivienda/__openerp__.py'
--- l10n_cr_account_banking_cr_davivienda/__openerp__.py	2013-03-14 15:57:05 +0000
+++ l10n_cr_account_banking_cr_davivienda/__openerp__.py	2013-05-06 01:43:13 +0000
@@ -27,7 +27,7 @@
     'author': 'CLEARCORP S.A.',
     'website': 'http://www.clearcorp.co.cr',
     'category': 'Account Banking',
-    'depends': ['account_banking'],
+    'depends': ['account_banking','account_parser_type'],
     'init_xml': [],
     'update_xml': [],
     'demo_xml': [],

=== modified file 'l10n_cr_account_banking_cr_lafise/__openerp__.py'
--- l10n_cr_account_banking_cr_lafise/__openerp__.py	2013-03-14 15:57:05 +0000
+++ l10n_cr_account_banking_cr_lafise/__openerp__.py	2013-05-06 01:43:13 +0000
@@ -27,7 +27,7 @@
     'author': 'CLEARCORP S.A.',
     'website': 'http://www.clearcorp.co.cr',
     'category': 'Account Banking',
-    'depends': ['account_banking'],
+    'depends': ['account_banking','account_parser_type'],
     'init_xml': [],
     'update_xml': [],
     'demo_xml': [],

=== modified file 'l10n_cr_account_banking_cr_lafise/lafise_parser.py'
--- l10n_cr_account_banking_cr_lafise/lafise_parser.py	2013-03-14 15:57:05 +0000
+++ l10n_cr_account_banking_cr_lafise/lafise_parser.py	2013-05-06 01:43:13 +0000
@@ -58,6 +58,7 @@
         lines = []
         line_dict = {}
         count = 1
+        currency_code = ''
         
         line_dict = {
             'transref': '', # _transmission_number
@@ -72,7 +73,7 @@
         }        
         #transmission_number and bookingdate -> Date when make the extract import.
         date_obj= datetime.now()
-        line_dict['transref'] = date_obj.strftime("%d-%m-%Y %H:%M:%S")
+        line_dict['transref'] = date_obj
         
         #delete blank rows
         for row in rows:
@@ -80,19 +81,27 @@
             if len(values) > 0:
                 lines.append(values)
         
-        #search the row #16 (after delete blank rows) and extract account, currency and ending_balance.
-        #the line 23 contain the initial_balance (position 5)
-        #lines is a list of lists.
-        
+        #lines is a list of lists.        
         #First, check if the account in the wizard match with the account in the file. 
         if self.match_account(lines, kwargs['account_number']):        
+            #extract from the wizard the account
+            line_dict['account_number'] = kwargs['account_number']           
+            
             for list in lines:
+                #currency_code in th file
+                if count == 4:
+                    currency = list[4]
+                    
+                    if "COL" in currency:
+                        currency_code = 'CRC'
+                        
+                    elif "USD" in currency:
+                        currency_code = 'USD'
+                    
+                    line_dict['currencycode'] = currency_code
+                
+                #initial balance
                 if count == 16:
-                    line_dict['account_number'] = self.extract_number(list[0])
-                    line_dict['currencycode'] = list[3]
-                    line_dict['endingbalance'] = self.extract_float(list[6]).replace(",","")
-                
-                elif count == 23:
                     line_dict['startingbalance'] =  self.extract_float(str(list[5]).replace(",",""))
                 
                 #interrupted the cycle, because the information is complete for the header.
@@ -102,17 +111,23 @@
             
             #statementnr
             line_dict['statementnr'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto Lafise ' + line_dict['account_number'] #Interval time of the file.
+                                    
+            #bookingdate
+            line_dict['bookingdate'] = date_obj
+            
+            #id
+            line_dict['id'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto Lafise ' + line_dict['account_number']            
+             
+            #ending_balance 
+            list = self.clean_special_characters_list(lines) #clean all the special characters and the rows without information
+            result = self.calculate_final_balance(list)
+            line_dict['endingbalance'] = float(line_dict['startingbalance']) - float(result['debit']) + float(result['credit'])
             
             #amount
             line_dict['ammount'] = float(line_dict['startingbalance']) + float(line_dict['endingbalance'])
             
-            #bookingdate
-            line_dict['bookingdate'] = date_obj.strftime("%d-%m-%Y %H:%M:%S")
-            
-            #id
-            line_dict['id'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto Lafise ' + line_dict['account_number']
-            
             return line_dict
+        
         else:
              raise osv.except_osv(_('Error'),
                         _('Error en la importación! La cuenta especificada en el archivo no coincide con la seleccionada en el asistente de importacion'))
@@ -133,58 +148,49 @@
             'creditmarker': '',
         }
         
-        lines = []
+        lines = clean_list = []
         statements = [] 
         currencycode = records['currencycode']
-        count = 1 #in line 24 start the statements.
+        count = 1 #in line 18 start the statements.
         
         #delete blank rows
         for row in rows:
             values = [col.text for col in row]
             if len(values) > 0:
                 lines.append(values)
+        
+        #clear lines of special characters
+        clean_list = self.clean_special_characters_list(lines)
 
-        for line in lines:
-             #In line 24 start the statements (in movements format)
-             if (count >= 24): 
-                #The final line (**** SALDO FINAL ****) must be largest than 3 celds,
-                #because the expresion is in the celd 2 (0,1,2)
-                if len(line) >= 3: 
-                    #the function clean_special_characters remove '\r\n' and '\t'
-                    try:
-                        str_line = self.clean_special_characters(line[2])  
-                        #The string str_line don't have blank spaces, son instance **** SALDO FINAL **** find ****SALDOFINAL****
-                        if (str_line != "****SALDOFINAL****"):
-                            #effective_date                  
-                            date_str = self.extract_date_regular_expresion(self.clean_special_characters(line[0]))
-                            date = datetime.strptime(date_str, "%d/%m/%y")               
-                            mapping['effective_date'] = date #fecha_contable.
-                            
-                            #execution_date
-                            mapping['execution_date'] = date #fecha_movimiento                       
-                           
-                            mapping['local_currency'] = currencycode
-                            mapping['transfer_type'] = 'NTRF'
-                            mapping['reference'] = self.extract_number(self.clean_special_characters(line[1]))
-                            mapping['message'] = str_line               
-                            mapping['name'] = str_line
-                            mapping['id'] = str_line
-                            
-                            debit = float(self.extract_float(self.clean_special_characters(line[3])))
-                            credit = float(self.extract_float(self.clean_special_characters(line[4])))
-                                            
-                            if (credit > 0.0): #in this case, credit is a input of money
-                                mapping['transferred_amount'] = credit
-                                mapping['creditmarker'] = 'C'
-                                                  
-                            else: #debit is output
-                                mapping['transferred_amount'] =  -debit
-                            
-                            statements.append(copy(mapping))
-                    except:
-                        #end of the file.
-                        break
-             count +=1      
+        for line in clean_list:
+            #effective_date                  
+            date_str = self.extract_date_regular_expresion(self.clean_special_characters(line[0]))
+            date = datetime.strptime(date_str, "%d/%m/%y")               
+            mapping['effective_date'] = date #fecha_contable.
+            
+            #execution_date
+            mapping['execution_date'] = date #fecha_movimiento                       
+           
+            str_line = self.clean_special_characters(line[2])
+            
+            mapping['local_currency'] = currencycode
+            mapping['transfer_type'] = 'NTRF'
+            mapping['reference'] = self.extract_number(self.clean_special_characters(line[1]))
+            mapping['message'] = str_line               
+            mapping['name'] = str_line
+            mapping['id'] = str_line
+            
+            debit = float(self.extract_float(self.clean_special_characters(line[3])))
+            credit = float(self.extract_float(self.clean_special_characters(line[4])))
+                            
+            if (credit > 0.0): #in this case, credit is a input of money
+                mapping['transferred_amount'] = credit
+                mapping['creditmarker'] = 'C'
+                                  
+            else: #debit is output
+                mapping['transferred_amount'] =  -debit
+            
+            statements.append(copy(mapping))
 
         return statements    
     
@@ -206,28 +212,6 @@
         
         #Set the header for the stament.
         matchdict = self.statement_record(rec, **kwargs);
-
-        # Remove members set to None
-        matchdict = dict( [( k, v ) for k, v in matchdict.iteritems() if v] )
-
-        matchkeys = set( matchdict.keys() )
-        needstrip = set( [ 'transref', 'account_number', 'statementnr', 'currencycode', 'endingbalance', 'bookingdate'] )
-
-        for field in matchkeys & needstrip:
-            matchdict[field] = matchdict[field].strip()
-
-        # Convert to float. Comma is decimal separator
-        needsfloat = set( ["startingbalance", "endingbalance", "amount"] )
-        for field in matchkeys & needsfloat:
-            matchdict[field] = float( matchdict[field].replace( ',', '.' ) )
-
-        # Convert date fields
-        needdate = set( ["bookingdate"] )
-                
-        for field in matchkeys & needdate:            
-            datestring = matchdict[field]
-            date_obj= datetime.strptime(datestring, "%d-%m-%Y %H:%M:%S")
-            matchdict[field] = date_obj
         
         return matchdict
         
@@ -276,23 +260,52 @@
             cad = cad + character       
         return cad
     
-    #clear special characters in a row. 
+    #clear special characters in a specific celd. 
     def clean_special_characters(self, text_celd):
-        special_characters = {'\r\n':'','\t':''," ":''}
-         
+        special_characters = {'\r\n':'','\t':''}
+        
         for i, j in special_characters.iteritems():
             text = text_celd.replace(i, j)    
-            
+        
         #remove all the blank space.
-        return re.sub(r'\s', '', text)
+        #return re.sub(r'\s', '', text)
+        return text
+    
+    #clear special characters in a specific row. 
+    def clean_special_characters_list(self, lines):    
+        new_row = list = []
+        special_characters = {'\r\n':'','\t':'','\r':'','\n':'','\\t':'','\t':''}
+        count = 1
+
+        for l in lines:
+            if (count >= 18): #in the line 18 start the statements                
+                if len(list) == 0:
+                    list = []
+                    
+                for celd in l:
+                    if celd != None:
+                        for i, j in special_characters.iteritems():
+                            text = celd.replace(i, j)
+                            text = re.sub(r'\t', '', text) #'\t' is the "tab" character
+                            
+                        if text != '':                      
+                            new_row.append(text)
+                
+                if len(new_row) > 0:
+                    list.append(new_row) #list containt all the rows clean 
+                new_row = []
+
+            count +=1
+            
+        return list
     
     #Return true if the account selected in the wizard match with the account in the file.
     def match_account(self, lines, account_wizard):
         count = 1
         acc_number = ''
         for list in lines:
-            if count == 16:
-                acc_number= self.extract_number(list[0])
+            if count == 4:
+                acc_number= self.extract_number(list[1])
                 break
             else:
                 count +=1
@@ -303,4 +316,21 @@
         else:
             return False
     
+    #List is the list of the statements, the method calculate the final_balance 
+    #with the debit and credit
+    def calculate_final_balance(self, list):
+        result = {'debit': 0.0, 'credit':0.0}
+        total_debit = total_credit = 0.0
+        
+        for line in list:
+            debit = float(self.extract_float(self.clean_special_characters(line[3])))
+            credit = float(self.extract_float(self.clean_special_characters(line[4])))
+            
+            total_debit += debit
+            total_credit += credit
+        
+        result ['debit'] = total_debit
+        result ['credit'] = total_credit
+        
+        return result
         
\ No newline at end of file


Follow ups