~cv.clearcorp/openerp-costa-rica/7.0-fix_detail_reports

« back to all changes in this revision

Viewing changes to l10n_cr_account_banking_cr_davivienda/davivienda_parser.py

[MRG] Fixed error messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    #Define the header for the extract to import.
36
36
    '''
37
37
     ** Kwargs parameter is used for a dynamic list of parameters. 
38
 
        The wizard imported extracts used in all parsers and not all parsers have all the necessary information in your file, 
 
38
        The wizard imported extracts used in all parsers and not 
 
39
        all parsers have all the necessary information in your file, 
39
40
        so get information from the wizard and passed by the ** kwargs. 
40
 
        Then in the parses that are needed, are extracted from the ** kwargs and if needed, 
41
 
        the parser still works the same way without this parameter.
42
 
        
43
 
        The rest of the methods must receive this parameter. (As the method that parse the header and the lines). 
44
 
        
45
 
        If you need a new parameter, you specify its name and value, using the ** kwargs is a dictionary, 
 
41
        Then in the parses that are needed, are extracted from the ** kwargs
 
42
        and if needed, the parser still works the same way without this parameter.
 
43
        
 
44
        The rest of the methods must receive this parameter. (As 
 
45
        the method that parse the header and the lines). 
 
46
        
 
47
        If you need a new parameter, you specify its name and value,
 
48
        using the ** kwargs is a dictionary, 
46
49
        extract its value, with the respective key
47
50
    '''
48
51
    def statement_record ( self, rec, **kwargs):
61
64
            'id': '',
62
65
        }
63
66
        
64
 
        #Separe the file in statements
 
67
        #Split the file in statements
65
68
        list_split = rec.split('\n')
66
69
        #Obtain the first line to know the account number
67
70
        fist_line = list_split[1]
70
73
        account_number_wizard = kwargs['account_number']#from wizard
71
74
        account_number_file = first_line_split[11]#from file.
72
75
        
73
 
        #if the account_number in the file match with the account selected in the wizard, return True
 
76
        #if the account_number in the file match with the account
 
77
        #selected in the wizard, return True
74
78
        if account_number_file.find(account_number_wizard) > -1:
75
 
            #currency_code (local_currency in the stament) extracted from account_number object from the wizard.
76
 
            #account_number (local_account) extracted from account_number object from the wizard.
77
 
            #date_to_str and date_from_str are the dates in wizard, both are strings
 
79
            #currency_code (local_currency in the stament)
 
80
            #extracted from account_number object from the wizard.
 
81
            #account_number (local_account) extracted from 
 
82
            #account_number object from the wizard.
 
83
            #date_to_str and date_from_str are the dates in
 
84
            #wizard, both are strings
78
85
            #the parameters come from davivienda_format in parser class.
79
86
            line_dict['account_number'] = kwargs['account_number']
80
87
            
81
88
            line_dict['currencycode'] = kwargs['local_currency']
82
89
            
83
 
            line_dict['statementnr'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + 'Extracto Davivienda ' + line_dict['account_number'] #Interval time of the file.
 
90
            line_dict['statementnr'] = kwargs['date_from_str'] + ' - '+ \
 
91
            kwargs['date_to_str'] + 'Extracto Davivienda ' + \
 
92
            line_dict['account_number'] #Interval time of the file.
84
93
             
85
94
            startingbalance = endingbalance = 0.0
86
95
            
93
102
            #with the first line compute the initial_balance
94
103
            fist_line = list_split[1]
95
104
            first_line_split = fist_line.split(';')
96
 
            startingbalance = float(first_line_split[5].replace(",","")) + float(first_line_split[3].replace(",","")) - float(first_line_split[4].replace(",",""))
 
105
            startingbalance = float(first_line_split[5].replace(",","")) + \
 
106
            float(first_line_split[3].replace(",","")) - \
 
107
            float(first_line_split[4].replace(",",""))
97
108
            line_dict['startingbalance'] =  str(startingbalance)
98
109
            
99
110
            #the ending_balance is the balance of the last line.        
111
122
            line_dict['endingbalance'] =  str(endingbalance)
112
123
            
113
124
            line_dict['amount'] = str(startingbalance + endingbalance)
114
 
            line_dict['id'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto Davivienda ' + line_dict['account_number']
 
125
            line_dict['id'] = kwargs['date_from_str'] + ' - ' + \
 
126
            kwargs['date_to_str'] + ' Extracto Davivienda ' + \
 
127
            line_dict['account_number']
115
128
            
116
129
            return line_dict
117
130
        
118
131
        else:
119
 
            raise osv.except_osv(_('Error'),
120
 
                        _('Error en la importación! La cuenta especificada en el archivo no coincide con la seleccionada en el asistente de importacion'))
 
132
            raise osv.except_osv(_('Import Error'),
 
133
                        _('The account specified in the file does not'
 
134
                          ' match the account selected in wizard'))
121
135
    
122
136
    '''
123
 
    Parse all the lines in the file. Once the header is parser, the next step are the lines.
 
137
    Parse all the lines in the file. Once the header
 
138
    is parser, the next step are the lines.
124
139
    '''     
125
140
    def statement_lines ( self, rec ):
126
141
        parser = DaviviendaParser()
158
173
            #effective_date
159
174
            date_str = line[0].replace("/","-")
160
175
            date= datetime.strptime(date_str, "%d-%m-%Y")               
161
 
            mapping['effective_date'] = date #fecha_contable.                        
 
176
            mapping['effective_date'] = date
162
177
            #execution_date
163
 
            mapping['execution_date'] = date #fecha_movimiento
 
178
            mapping['execution_date'] = date
164
179
                                   
165
180
            mapping['transfer_type'] = 'NTRF'
166
181
            mapping['reference'] = line[2] #Ref 1 
194
209
    
195
210
    """
196
211
    ** Kwargs parameter is used for a dynamic list of parameters. 
197
 
        The wizard imported extracts used in all parsers and not all parsers have all the necessary information in your file, 
 
212
        The wizard imported extracts used in all parsers 
 
213
        and not all parsers have all the necessary information in your file, 
198
214
        so get information from the wizard and passed by the ** kwargs. 
199
215
        Then in the parses that are needed, are extracted from the ** kwargs and if needed, 
200
216
        the parser still works the same way without this parameter.
201
217
        
202
 
        The rest of the methods must receive this parameter. (As the method that parse the header and the lines). 
 
218
        The rest of the methods must receive this parameter. (As the 
 
219
        method that parse the header and the lines). 
203
220
        
204
 
        If you need a new parameter, you specify its name and value, using the ** kwargs is a dictionary, 
 
221
        If you need a new parameter, you specify its name and value, 
 
222
        using the ** kwargs is a dictionary, 
205
223
        extract its value, with the respective key
206
224
    """
207
225
    
216
234
        #matchdict = dict( [( k, v ) for k, v in matchdict.iteritems() if v] )
217
235
 
218
236
        matchkeys = set( matchdict.keys() )
219
 
        needstrip = set( [ 'transref', 'account_number', 'statementnr', 'currencycode', 'endingbalance', 'bookingdate'] )
 
237
        needstrip = set( [ 'transref', 'account_number', 'statementnr',
 
238
                          'currencycode', 'endingbalance', 'bookingdate'])
220
239
 
221
240
        for field in matchkeys & needstrip:
222
241
            matchdict[field] = matchdict[field].strip()