I have the following codes to print a receipt generated from database for a specific customer. The commented area of hard coding with the customer’s name in the database works fine but the lines below it doesn’t work dynamically by selecting the customer from the combobox
def listReceipts(self):
self.displaySales()
self.receipt.ui.tableWidget.setRowCount(0)
con = sqlite3.connect("ayelojadb.db")
con.execute("PRAGMA foreign_keys = 1")
cur = con.cursor()
# cmd = "SELECT * FROM t_sales WHERE stud_name = 'John'"
# cur.execute(cmd)
# rows = cur.fetchall()
customer = self.ui.cust_comboBox_2.currentText()
cmd = "SELECT * FROM t_sales WHERE cust_name = ?"
cur.execute(cmd, (customer,))
rows = cur.fetchall()
for row_number, row_data in enumerate(rows):
self.receipt.ui.tableWidget.insertRow(row_number)
for column_number, column_data in enumerate(row_data):
it = QTableWidgetItem()
if column_number == 0:
pass
else:
it.setText(str(column_data))
self.receipt.ui.tableWidget.setItem(row_number, column_number, it)
self.receipt.ui.tableWidget.setColumnWidth(0,0)
self.receipt.ui.tableWidget.setColumnWidth(1,100)
self.receipt.ui.tableWidget.setColumnWidth(2,300)
self.receipt.ui.tableWidget.setColumnWidth(3,100)
self.receipt.ui.tableWidget.setColumnWidth(4,100)
#self.inher_list.ui.tableWidget.horizontalHeader().setDefaultSectionSize(170)
con.close()
def generatePDF(self):
self.listReceipts()
self.printPDF()