~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_bncr/bncr_parser.py

[MRG] Fixed error messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        #Split the file in statements
63
63
        list_split = rec.split('\n')        
64
64
       
65
 
        #currency_code (local_currency in the stament) extracted from account_number object from the wizard.
66
 
        #account_number (local_account) extracted from account_number object from the wizard.
67
 
        #date_to_str and date_from_str are the dates in wizard, both are strings
 
65
        #currency_code (local_currency in the stament) extracted 
 
66
        #from account_number object from the wizard.
 
67
        #account_number (local_account) extracted from account_number
 
68
        #object from the wizard. date_to_str and date_from_str are
 
69
        #the dates in wizard, both are strings
68
70
        
69
71
        line_dict['account_number'] = kwargs['account_number']
70
72
        
71
73
        line_dict['currencycode'] = kwargs['local_currency']
72
74
        
73
 
        line_dict['statementnr'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto BNCR ' + line_dict['account_number'] #Interval time of the file.
 
75
        line_dict['statementnr'] = kwargs['date_from_str'] + ' - '+ \
 
76
        kwargs['date_to_str'] + ' Extracto BNCR ' + \
 
77
        line_dict['account_number'] #Interval time of the file.
74
78
        
75
79
        #transmission_number (Date when done the import)
76
80
        date_obj= datetime.now()
79
83
        line_dict['bookingdate'] = date_obj.strftime("%d-%m-%Y %H:%M:%S")
80
84
        
81
85
        '''
82
 
            For the BNCR parser, the ending_balance comes from wizard. With total of debit and credit and the ending_balance
 
86
            For the BNCR parser, the ending_balance comes from wizard. With
 
87
            total of debit and credit and the ending_balance
83
88
            compute the initial_balance.
84
89
        '''
85
 
        #extract the total of debit and credit from the file. The last statements and compute the startingbalance
 
90
        #extract the total of debit and credit from the file.
 
91
        #The last statements and compute the startingbalance
86
92
        last_position = (len(list_split) - 1)
87
93
        last_line = list_split[last_position] 
88
94
        #last line can be blanck, find the last line with data.
120
126
        line_dict['endingbalance'] =  str(kwargs['ending_balance'])
121
127
        
122
128
        line_dict['ammount'] = startingbalance + endingbalance
123
 
        line_dict['id'] = kwargs['date_from_str'] + ' - '+ kwargs['date_to_str'] + ' Extracto BNCR ' + line_dict['account_number']
 
129
        line_dict['id'] = kwargs['date_from_str'] + ' - '+ \
 
130
        kwargs['date_to_str'] + ' Extracto BNCR ' + \
 
131
        line_dict['account_number']
124
132
        
125
133
        return line_dict
126
134
        
197
205
     
198
206
    """
199
207
    ** Kwargs parameter is used for a dynamic list of parameters. 
200
 
        The wizard imported extracts used in all parsers and not all parsers have all the necessary information in your file, 
 
208
        The wizard imported extracts used in all parsers and not 
 
209
        all parsers have all the necessary information in your file, 
201
210
        so get information from the wizard and passed by the ** kwargs. 
202
211
        Then in the parses that are needed, are extracted from the ** kwargs and if needed, 
203
212
        the parser still works the same way without this parameter.
204
213
        
205
 
        The rest of the methods must receive this parameter. (As the method that parse the header and the lines). 
 
214
        The rest of the methods must receive this parameter. (As the method 
 
215
        that parse the header and the lines). 
206
216
        
207
 
        If you need a new parameter, you specify its name and value, using the ** kwargs is a dictionary, 
 
217
        If you need a new parameter, you specify its name and value,
 
218
        using the ** kwargs is a dictionary, 
208
219
        extract its value, with the respective key
209
220
    """
210
221
    def parse_stamenent_record( self, rec, **kwargs):
218
229
        matchdict = dict( [( k, v ) for k, v in matchdict.iteritems() if v] )
219
230
 
220
231
        matchkeys = set( matchdict.keys() )
221
 
        needstrip = set( [ 'transref', 'account_number', 'statementnr', 'currencycode', 'endingbalance', 'bookingdate'] )
 
232
        needstrip = set( [ 'transref', 'account_number', 'statementnr',
 
233
                          'currencycode', 'endingbalance', 'bookingdate'] )
222
234
 
223
235
        for field in matchkeys & needstrip:
224
236
            matchdict[field] = matchdict[field].strip()
252
264
        output = []
253
265
 
254
266
        for rec in records:
255
 
            #parse_stament_record call the method that parse the header and the stament of the file.
 
267
            #parse_stament_record call the method that
 
268
            #parse the header and the stament of the file.
256
269
            output.append(self.parse_stamenent_record( rec ))
257
270
                
258
271
        return output