Skip to content

Commit

Permalink
improve line calculation to insert
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafaelrn committed Apr 23, 2024
1 parent 95504d2 commit 3f4803b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/functions/bd_transaction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,34 @@ def open_bd_bank():
return bd_sheet


line_to_insert = None

def insert_transaction(date_trx, account, original_description, document, entity_bank, type_trx, value, balance, id_bank):

global line_to_insert
print(f'Starting insert transaction - Date: {date_trx} - Account: {account} - Original Description: {original_description} - Document: {document} - Entity Bank: {entity_bank} - Type Trx: {type_trx} - Value: {value} - Balance: {balance}')
entity_bank = entity_bank.strip()

bd = open_bd_bank()
bd_pd = pd.DataFrame(bd.get_all_records(value_render_option='UNFORMATTED_VALUE'))

line = 0

# loop to check if the transaction already exists
for row in bd_pd.iterrows():

id_row = row[1]['ID_BANCO']
if line_to_insert is None:

if id_row != "":
line += 1
line_to_insert = 0

# loop to find the first empty line
for row in bd_pd.iterrows():


line += 2
print(f'ID to add to Bank: {id_bank} - LINE: {line}')
id_row = row[1]['ID_BANCO']

if id_row != "":
line_to_insert += 1

line_to_insert += 2


print(f'ID to add to Bank: {id_bank} - LINE: {line_to_insert}')

# Append new row
row = [id_bank, date_trx, account, original_description, document, entity_bank, type_trx, value, balance]
Expand All @@ -76,9 +82,10 @@ def insert_transaction(date_trx, account, original_description, document, entity
continue

print(f'Coluna: {coluna} - Conteudo: {conteudo}')
bd.update(f'{coluna}{line}', conteudo)
bd.update(f'{coluna}{line_to_insert}', conteudo)


line_to_insert += 1
msg = f'Lancamento inserido!! ID: {id_bank} - Data: {date_trx} - Conta: {account} - Descrição: {original_description} - Documento: {document} - Entidade: {entity_bank} - Tipo: {type_trx} - Valor: {value} - Saldo: {balance}'
print(msg)
return msg
Expand Down

0 comments on commit 3f4803b

Please sign in to comment.