I have a big problem with a part of my code:
the function below, it adds the values of the price column and the quantity column to extract the total amount of the order. But the price column is doubling the value and I can't find the error.
I've tried deleting the variable and clearing the memory cache, thinking it could be accumulating values.. but it's still the same!
This program is using pyqt6 and python3. is a program for issuing sales orders!
global row
# =============================================== SAVING VALUES INSERTED ON THE MAIN SCREEN IN VARIABLES
self.obter_resultado = self.ui.comboBox_produto.currentText()
self.obter_preco = (self.ui.insere_preco.text())
self.obter_quantide = (self.ui.insere_quantidade.text())
self.obter_cliente = (self.ui.insere_cliente.text())
self.obter_prazo = self.ui.comboBox_prazo.currentText()
self.obter_trasportadora = self.ui.comboBox_transport.currentText()
self.obter_frete = self.ui.comboBox_frete.currentText()
self.obter_num_pedido = (self.ui.insere_num_pedido.text())
self.obter_vendedor = self.ui.comboBox_vendedor.currentText()
self.obter_embalagem = self.ui.comboBox_embalagem.currentText()
self.obter_Nf = self.ui.checkBox_NF.isChecked()
self.obter_Snf = self.ui.checkBox_SNF.isChecked()
self.obter_obs = (self.ui.observacoes.text())
# =============================================== INSERTING PRICE, QUANTITY, PRODUCT AND PACKAGING IN THE "PRODUCTS" TABLE
self.ui.tabela_recebe_produto.setRowCount(len(self.obter_resultado))
self.ui.tabela_recebe_produto.setItem(row, 0, QtWidgets.QTableWidgetItem(self.obter_resultado))
self.ui.tabela_recebe_produto.setItem(row, 1, QtWidgets.QTableWidgetItem(self.obter_quantide + " kg"))
self.ui.tabela_recebe_produto.setItem(row, 2, QtWidgets.QTableWidgetItem("R$ " + self.obter_preco))
self.ui.tabela_recebe_produto.setItem(row, 3, QtWidgets.QTableWidgetItem(self.obter_embalagem))
row=row+1
# =============================================== SAVING VALUES TO A TEXT FILE
if os.path.isdir(r"C:\\Users\Public\Documents\Pie"):
print()
else:
os.mkdir(r"C:\\Users\Public\Documents\Pie")
try:
conteudo1 = open(f"C:\\Users\Public\Documents\Pie\Pedido_{self.obter_cliente}.txt", "r", encoding="utf-8").read()
except:
conteudo1 = ""
if re.search("PEDIDO DE VENDA..\n\nVENDEDOR:", conteudo1):
arq = open(f"C:\\Users\Public\Documents\Pie\Pedido_{self.obter_cliente}.txt", "w", encoding="utf-8")
arq.write(conteudo1+"PRODUTO: %s | QUANTIDADE: %s kg | PREÇO: R$ %s\r"%(self.obter_resultado, self.obter_quantide, self.obter_preco))
arq.close()
else:
arq = open(f"C:\\Users\Public\Documents\Pie\Pedido_{self.obter_cliente}.txt", "w", encoding="utf-8")
arq.write(conteudo1+"PEDIDO DE VENDA..\n\nVENDEDOR: %s\nCLIENTE: %s\nPRAZO: %s\nN°PEDIDO: %s\nNF: %s\nSnF: %s\nTRANSPORTADORA: %s\nFRETE: %s\nPRODUTO: %s | QUANTIDADE: %s kg | PREÇO: R$ %s\r\n\n Obs:%s\r"%(self.obter_vendedor, self.obter_cliente, self.obter_prazo, self.obter_num_pedido, self.obter_Nf, self.obter_Snf, self.obter_trasportadora, self.obter_frete, self.obter_resultado, self.obter_quantide, self.obter_preco, self.obter_obs))
arq.close()
# =============================================== GLOBAL VARIABLE TO CALCULATE FREIGHT
global qtdd
global valor
# =============================================== CALCULATION OF FINAL WEIGHT AND QUANTITY
valor = valor + float(self.obter_preco)
qtdd = qtdd + float(self.obter_quantide)
# =============================================== INSERT THE VALUE IN THE LABEL OF THE WEIGHT AND FINAL QUANTITY
valor_total = valor * qtdd
self.ui.recebe_peso_total.setText(str(qtdd))
self.ui.recebe_valor_total.setText(str(valor_total))```