def get_data(self, cr, uid, ids, recordlist, data): account_period_obj = self.pool.get('account.period') journal_obj = self.pool.get('account.journal') journal_code = journal_obj.browse(cr, uid, data['journal_id']).code bank_statements = [] bank_statement = {} for line in recordlist: if line[0:2] == '01': bank_statement = {} bank_statement["bank_statement_line"] = {} bank_statement_lines = {} num = int(line[19:20]) or 2 bank_statement["acc_number"] = line[21:32] bank_statement['date'] = conversion.str2date(line[34:40]) bank_statement['journal_id'] = data['journal_id'] period_id = account_period_obj.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 and period_id[0] or False bank_statement['state'] = 'draft' amount = line[91:104] amount, sign = letterconvert(amount) amount = list2float2(amount, num) bal_start = change_sign(amount, sign) bank_statement["balance_start"] = bal_start # bank_statement['name'] = False elif line[0:2] == '04': st_line = {} line_name = line[48:79] st_line['name'] = line[48:79] st_line['extra_note'] = line[48:79] st_line['ref'] = line[81:88] st_line['date'] = conversion.str2date(line[34:40]) num = int(line[19:20]) or 2 amount = line[91:104] amount, sign = letterconvert(amount) amount = list2float2(amount, num) amount = change_sign(amount, sign) # bal_start = list2float2(amount, num, sign) st_line['amount'] = amount if sign == '-': # if line[32:34] in ('01','11','23','96','62','67','70'): # st_line['amount'] = amount st_line['account_id'] = data['payable_id'] elif sign == '+': # elif line[32:34] in ('02','05'): # st_line['amount'] = amount st_line['account_id'] = data['receivable_id'] # else: # st_line['amount'] = amount # st_line['account_id'] = data['def_receivable'] st_line['partner_id'] = False bank_statement_lines[line_name] = st_line bank_statement["bank_statement_line"] = bank_statement_lines elif line[0:2] == '05': extra = line[48:79] st_line['extra_note'] += '\n' + line[48:79] elif line[0:2] == '07': num = int(line[19:20]) or 2 amount = line[91:104] amount, sign = letterconvert(amount) amount = list2float2(amount, num) bal_end = change_sign(amount, sign) # bal_end = list2float2(line[91:103], num) bank_statement["balance_end_real"] = bal_end bank_statements.append(bank_statement) return bank_statements
def parse_sequence( bank_statement, bank, cr, uid, ): pool = pooler.get_pool(cr.dbname) st_line = {} bank_statement_output = [] current = 0 while current < len(bank_statement): #if ':61:' in bank_statement[current]: if bank_statement[current].has_key(':61:'): # Pfff.. a line we can use. Gives us the date, debit/credit, and amount st_line['date'] = conversion.str2date( bank_statement[current][':61:'][0:6]) entry_date = time.strftime( '%Y-%m-%d', time.strptime( conversion.str2date(bank_statement[current][':61:'][0:6]), "%d/%m/%y")), st_line['val_date'] = time.strftime( '%Y-%m-%d', time.strptime( conversion.str2date(bank_statement[current][':61:'][0:6]), "%d/%m/%y")), st_line['entry_date'] = entry_date # Pfff...get amount amount = round(float(get_number(bank_statement[current][':61:'])), 2) st_line['amount'] = amount # Getting rich or poor if bank_statement[current][':61:'][6] == "D": st_line['account_id'] = bank['def_pay_acc'] st_line['amount'] = -st_line['amount'] # chek_ids did not work correctly because the amount could also be negativ amount = -amount else: st_line['account_id'] = bank['def_rec_acc'] # Well, that was the transaction, now the details, directly next line.. current += 1 if bank_statement[current].has_key(':68:'): st_line['free_comm'] = " " st_line['partner_id'] = 0 st_line['type'] = 'general' st_line['free_comm'] = " " st_line['partner_acc_number'] = get_acc_number( bank_statement[current][':68:']) st_line['cntry_number'] = get_acc_number( bank_statement[current][':68:']) st_line['contry_name'] = bank_statement[current][':68:'][ len(st_line['cntry_number']):] st_line['name'] = bank_statement[current][':68:'][ len(st_line['cntry_number']):] st_line[ 'ref'] = " " # Sometimes .. there is no ref. Still, it is being used by other scripts. # Houston, we have a problem.. ING uses nicely a second :86: code, Postbank does not ... (back to the filling of the list,.done) # See if we have a next rule, only description!! current += 1 if bank_statement[current].has_key(':68:'): st_line['ref'] = bank_statement[current][':68:'][0:] # extra comment.. filling the free_comm current += 1 if bank_statement[current].has_key(':68:'): st_line['free_comm'] = bank_statement[current][':68:'][ 0:] else: current -= 1 # check if there is already a statement like this... check_ids = pool.get('account.bank.statement.line').search( cr, uid, [('amount', '=', amount), ('date', '=', entry_date), ('name', '=', st_line['name'])]) # check if there already is a relation ..., and use the ID bank_ids = pool.get('res.partner.bank').search( cr, uid, [('acc_number', '=', st_line['partner_acc_number'])]) if bank_ids: bank = pool.get('res.partner.bank').browse(cr, uid, bank_ids[0], context={}) if bank.partner_id: st_line['partner_id'] = bank.partner_id.id partner = pool.get('res.partner').browse(cr, uid, bank.partner_id, context={}) 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' # ..Let see if we can make that just one line of imput print st_line if not check_ids: bank_statement_output.append(st_line.copy()) current += 1 return bank_statement_output
def parse_sequence(bank_statement,bank, cr, uid,): pool = pooler.get_pool(cr.dbname) st_line = {} bank_statement_output=[] current=0 while current < len(bank_statement): #if ':61:' in bank_statement[current]: if bank_statement[current].has_key(':61:'): # Pfff.. a line we can use. Gives us the date, debit/credit, and amount st_line['date']=conversion.str2date(bank_statement[current][':61:'][0:6]) entry_date = time.strftime('%Y-%m-%d',time.strptime(conversion.str2date(bank_statement[current][':61:'][0:6]),"%d/%m/%y")), st_line['val_date'] = time.strftime('%Y-%m-%d',time.strptime(conversion.str2date(bank_statement[current][':61:'][0:6]),"%d/%m/%y")), st_line['entry_date']=entry_date # Pfff...get amount amount =round(float(get_number(bank_statement[current][':61:'])),2) st_line['amount']=amount # Getting rich or poor if bank_statement[current][':61:'][6] == "D": st_line['account_id'] = bank['def_pay_acc'] st_line['amount'] = - st_line['amount'] # chek_ids did not work correctly because the amount could also be negativ amount = - amount else: st_line['account_id'] = bank['def_rec_acc'] # Well, that was the transaction, now the details, directly next line.. current += 1 if bank_statement[current].has_key(':68:'): st_line['free_comm'] = " " st_line['partner_id'] = 0 st_line['type'] = 'general' st_line['free_comm'] = " " st_line['partner_acc_number'] = get_acc_number(bank_statement[current][':68:']) st_line['cntry_number'] = get_acc_number(bank_statement[current][':68:']) st_line['contry_name'] =bank_statement[current][':68:'][len(st_line['cntry_number']):] st_line['name'] = bank_statement[current][':68:'][len(st_line['cntry_number']):] st_line['ref'] =" " # Sometimes .. there is no ref. Still, it is being used by other scripts. # Houston, we have a problem.. ING uses nicely a second :86: code, Postbank does not ... (back to the filling of the list,.done) # See if we have a next rule, only description!! current += 1 if bank_statement[current].has_key(':68:'): st_line['ref'] =bank_statement[current][':68:'][0:] # extra comment.. filling the free_comm current += 1 if bank_statement[current].has_key(':68:'): st_line['free_comm'] = bank_statement[current][':68:'][0:] else: current -= 1 # check if there is already a statement like this... check_ids = pool.get('account.bank.statement.line').search(cr,uid,[('amount','=',amount), ('date','=',entry_date),('name','=',st_line['name'])]) # check if there already is a relation ..., and use the ID bank_ids = pool.get('res.partner.bank').search(cr,uid,[('acc_number','=',st_line['partner_acc_number'])]) if bank_ids: bank = pool.get('res.partner.bank').browse(cr,uid,bank_ids[0],context={}) if bank.partner_id: st_line['partner_id'] = bank.partner_id.id partner = pool.get('res.partner').browse(cr,uid,bank.partner_id,context={}) 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' # ..Let see if we can make that just one line of imput print st_line if not check_ids: bank_statement_output.append(st_line.copy()) current += 1 return bank_statement_output
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
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