Exemplo n.º 1
0
    def CadastraVendaDB(self):
        # current datetime in UTC
        dt = datetime.now()
        utc_time = dt.replace(tzinfo=timezone.utc)

        INSERIR = CrudVenda()
        INSERIR.id = self.tx_IdVenda.text()
        INSERIR.idCliente = self.tx_IdCliente.text().upper()
        INSERIR.tipoPagamento = self.cb_TipoPagamento.currentData()
        INSERIR.dataVenda = utc_time
        INSERIR.subtotal = self.tx_SubTotal.text().replace(",", ".")
        INSERIR.desconto = self.tx_Desconto.text().replace(",", ".")
        INSERIR.addVenda()

        ATUALIZAR_ESTOQUE = CrudProduto()
        INSERIR_ITENS = CrudRelVenda()
        for row in range(self.tb_Itens.rowCount()):
            idProduto = self.tb_Itens.item(row, 1).text()
            qtd = self.tb_Itens.item(row, 3).text()
            INSERIR_ITENS.idVenda = self.tx_IdVenda.text()
            INSERIR_ITENS.idProduto = idProduto
            INSERIR_ITENS.qtd = qtd
            INSERIR_ITENS.valorUnitario = self.tb_Itens.item(row, 4).text()
            INSERIR_ITENS.valorTotal = self.tb_Itens.item(row, 5).text()
            INSERIR_ITENS.addItens()
            ATUALIZAR_ESTOQUE.id = idProduto
            ATUALIZAR_ESTOQUE.DetalhamentoProdutoId()
            ATUALIZAR_ESTOQUE.qtdEstoque = int(
                ATUALIZAR_ESTOQUE.qtdEstoque) - int(qtd)
            ATUALIZAR_ESTOQUE.updateProduto()
        self.janelaVendas()
Exemplo n.º 2
0
 def CadastraProdutoDB(self):
     INSERIR = CrudProduto()
     INSERIR.id = self.tx_idProduto.text()
     INSERIR.produto = self.tx_NomeProduto.text().upper()
     INSERIR.descricao = self.tx_Descricao.text().upper()
     # converts image for base64 to save in DB
     if self.lb_FotoProduto.pixmap():
         imagem = QPixmap(self.lb_FotoProduto.pixmap())
         data = QByteArray()
         buf = QBuffer(data)
         imagem.save(buf, 'PNG')
         INSERIR.imagem = str(data.toBase64()).encode('utf8')[2:-1]
     else:
         INSERIR.imagem = False
     INSERIR.categoria = self.cb_Categoria.currentData()
     INSERIR.marca = self.cb_Marca.currentData()
     INSERIR.qtdMinimoEstoque = self.tx_QtdMinimoEstoque.text()
     INSERIR.qtdEstoque = self.tx_QtdEstoque.text()
     INSERIR.valorUnitario = self.tx_ValorUnitario.text().replace(",", ".")
     INSERIR.addProduto()
     self.janelaProdutos()