Пример #1
0
def get_data(self, bankData, bank_statement):
	   
      pool = pooler.get_pool(cr.dbname)
      
      bal_end = bank_statement['bal_end']
      bank_statement_lines={}
      bank_statements=[]
      line_name = 0
      st_line_name = line_name
      code4 = 0
      date_format = "%d%m%y"
      
      # parse every line in the file and get the right data
      for line in bankData:
         if len(line) <= 23:  # the end of the file has an empty line
            pass
         else:
            # check if bankaccount in the file matches with the bankaccount of the database
            bankaccount = line[0:10]
            # Look if we can match our number with a number in the list
            if bankaccount.lower() in bank_statement["acc_number"]:
               # look for the recordtype
               # 2 is the baserecord. We can also have 3 and 4. These are followrecords.
               if line[23] == '2' and code4 == 0:
                  st_line_name = line_name
                  st_line = {}
                  st_line['statement_id']=0
                  st_line['name'] = line[48:72]
                  date = conversion.str2date(line[87:93], date_format)
                  st_line['date'] = date # boekingsdatum
                  st_line_amt = conversion.list2float(line[73:86], date_format)
                  val_date = conversion.str2date(line[93:99], date_format)
                  
                  if line[86] == "D": 
                     st_line_amt = - st_line_amt
                     st_line['account_id'] = bank_statement['def_pay_acc']
                  else:
                     st_line['account_id'] = bank_statement['def_rec_acc']
                    
                  st_line['entry_date'] = date
                  st_line['val_date'] = val_date
                              
                  st_line['partner_id']=0
                  st_line['amount'] = st_line_amt
                  st_line['type'] = 'general'
                 
                  st_line_partner_acc = str(line[38:48]).strip()
                  if st_line_partner_acc[:1] == '0':
                  	st_line_partner_acc = st_line_partner_acc[1::]
                  	
                  st_line['partner_acc_number'] = st_line_partner_acc 
                  	 	  
                  cntry_number=st_line_partner_acc
                  contry_name=line[48:72]
                  bank_ids = pool.get('res.partner.bank').search(cr,uid,[('acc_number', '=', st_line_partner_acc)])
                  
                  if bank_ids:
                     bank = pool.get('res.partner.bank').browse(cr,uid,bank_ids[0],context={})
                     st_line['cntry_number']=cntry_number
                     st_line['contry_name']=contry_name
      
                     if st_line and bank.partner_id:
                        st_line['partner_id']=bank.partner_id.id
                        
                        # Create a check if we don't already imported this statement
                        # We make an unique check in the database with
                        # partner, date and amount
                        check_ids = pool.get('account.bank.statement.line').search(cr,uid,[('amount','=',st_line_amt), ('date','=',st_line['entry_date']),('partner_id','=',bank.partner_id.id)])
                                         
                                
                        # check if the partner is a supplier or customer
                        # if both, we don't add a account due to credit invoices		
                        partner = pool.get('res.partner').browse(cr,uid,bank.partner_id,context={})
                        
                        st_line['type']='general'
                        
                        if bank.partner_id.supplier == True and bank.partner_id.customer == False:
                        	st_line['account_id']= bank.partner_id.property_account_receivable.id
                        	st_line['type']='supplier'

                        elif bank.partner_id.customer == True and bank.partner_id.supplier == False :
                        	st_line['account_id']= bank.partner_id.property_account_payable.id
                        	st_line['type']='customer'

                        #if st_line['amount'] < 0 :
                        #   st_line['account_id']= bank.partner_id.property_account_payable.id
                        #else :
                        #   st_line['account_id']= bank.partner_id.property_account_receivable.id
   
                  else:
                     st_line['cntry_number']=cntry_number
                     st_line['contry_name']=contry_name
                     
                     # Create a check if we don't already imported this statement
                     # We make an unique check in the database with
                     # name, date and amount
                     check_ids = pool.get('account.bank.statement.line').search(cr,uid,[('amount','=',st_line_amt), ('date','=',st_line['entry_date']), ('name','=',contry_name)])               
                 
                  st_line['free_comm']= ''
                  st_line['ref']=''
                
               elif line[23] == '3' and code4 == 0 :      # get some information about the transaction
                  st_line['free_comm']=line[56:119]
                  refe = line[56:119].split(' ')
                  stri = ''
                  for t in refe:
                  	if t.strip():
                        	stri = stri + ' ' + ''.join(t.strip())
                  
                  st_line['ref']=stri
                  code4 = int(line[120])
                  if not check_ids:
                     line_name += 1
                     st_line_name = line_name      
                     
               elif line[23] == '4':      # get some more information about the transaction
                  st_line['free_comm'] = st_line['free_comm'] + "\n" + line[24:119]
                  code4 = code4 - 1
               
               if not check_ids:   
                 bank_statement_lines[line_name]=st_line
               #  bank_statements.append(st_line)    
         

           # end if
      # end for
      
      
      
      # delete latest row from the list because its an empty row
      if len(bank_statement_lines) >= 1:
         del bank_statement_lines[ line_name ]  # delete latest row from the list
         for test in bank_statement_lines:
            bank_statements.append(bank_statement_lines[test])
         
      # count the end balance
#      for value in bank_statement_lines:
#         line=bank_statement_lines[value]
#         bal_end += line['amount']

#      bank_statement["balance_end_real"]= bal_end
#      bank_statement["bank_statement_line"]=bank_statement_lines
     
      return bank_statements
Пример #2
0
def get_data(self, cr, uid, bankData, bank_statement):
      pool = pooler.get_pool(cr.dbname)
   
      bal_end = bank_statement['bal_end']
      bank_statement_lines={}
      bank_statements=[]
      line_name = 0
      str_log = ""
      err_log = ""
      str_log1 = ""
      st_line_name = line_name
    
      # parse every line in the file and get the right data
      for line in bankData:
        if line[0] == '0':
            # header data
#            bank_statement={}
#            bank_statement_lines={}
            bank_statement["bank_statement_line"]={}
            #bank_statement['date'] = conversion.str2date(line[5:11])
            #period_id = pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime("%y/%m/%d",time.strptime(bank_statement['date'],"%d/%m/%y"))),('date_stop','>=',time.strftime("%y/%m/%d",time.strptime(bank_statement['date'],"%d/%m/%y")))])
            #period_id = pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime('%Y-%m-%d',time.strptime(bank_statement['date'],"%y/%m/%d"))),('date_stop','>=',time.strftime('%Y-%m-%d',time.strptime(bank_statement['date'],"%y/%m/%d")))])
            #bank_statement['period_id'] = period_id[0]
            #bank_statement['state']='draft'
        elif line[0] == '1':
            # old balance data
            bal_start = conversion.list2float(line[43:58])
            if line[42] == '1':
                bal_start = - bal_start
            bank_statement["balance_start"]= bal_start
            bank_statement["acc_number"]=line[5:17]
            bank_statement["acc_holder"]=line[64:90]

        elif line[0]=='2':
            # movement data record 2
            if line[1]=='1':
                # movement data record 2.1
                st_line = {}
                st_line['statement_id']=0
                st_line['name'] = line[2:10]
                st_line['date'] = conversion.str2date(line[115:121])
                st_line_amt = conversion.list2float(line[32:47])

                if line[61]=='1':
                    st_line['ref']=(line[65:77])
                    st_line['free_comm']=''
                else:
                    st_line['free_comm']=line[62:115]
                    st_line['ref']=''

                st_line['val_date']=time.strftime('%Y-%m-%d',time.strptime(conversion.str2date(line[47:53]),"%y/%m/%d")),
                st_line['entry_date']=time.strftime('%Y-%m-%d',time.strptime(conversion.str2date(line[115:121]),"%y/%m/%d")),
                st_line['partner_id']=0
                if line[31] == '1':
                    st_line_amt = - st_line_amt
                    st_line['account_id'] = bank_statement['def_pay_acc']
                else:
                    st_line['account_id'] = bank_statement['def_rec_acc']
                st_line['amount'] = st_line_amt
                bank_statement_lines[st_line['name']]=st_line
                bank_statement["bank_statement_line"]=bank_statement_lines

            elif line[1] == '3':
                # movement data record 3.1
                st_line_name = line[2:10]
                st_line_partner_acc = str(line[10:47]).strip()
                cntry_number=line[10:47]
                contry_name=line[47:125]
                #bank_ids = pool.get('res.partner.bank').search(cr,uid,[('number','=',st_line_partner_acc)])
                bank_ids = pool.get('res.partner.bank').search(cr,uid,[('acc_number','=',st_line_partner_acc)])
                if bank_ids:
                    bank = pool.get('res.partner.bank').browse(cr,uid,bank_ids[0],context={})
                    line=bank_statement_lines[st_line_name]
                    line['cntry_number']=cntry_number
                    line['contry_name']=contry_name

                    if line and bank.partner_id:
                        line['partner_id']=bank.partner_id.id
                        if line['amount'] < 0 :
                            line['account_id']=bank.partner_id.property_account_payable.id
                        else :
                            line['account_id']=bank.partner_id.property_account_receivable.id

                        bank_statement_lines[st_line_name]=line
                else:
                    line=bank_statement_lines[st_line_name]
                    line['cntry_number']=cntry_number
                    line['contry_name']=contry_name
                    bank_statement_lines[st_line_name]=line


                bank_statement["bank_statement_line"]=bank_statement_lines
        elif line[0]=='3':
            pass
        elif line[0]=='8':
            # new balance record
            bal_end = conversion.list2float(line[42:57])
            if line[41] == '1':
                bal_end = - bal_end
            bank_statement["balance_end_real"]= bal_end

        elif line[0]=='9':
            # footer record
            pass
            #bank_statements.append(bank_statement)
     #end for
      return bank_statement