Example #1
0
    def __search(self):
        nameText = self.lineEdit.text()
        sdate = self.startCalenderLineEdit.date().toPython()
        startDate = datetime.datetime.combine(sdate,
                                              datetime.datetime.min.time())

        eDate = self.stopCalenderLineEdit.date().toPython()
        stopDate = datetime.datetime.combine(eDate,
                                             datetime.datetime.max.time())

        limit = self.limitSpinbox.value()
        query = self.databaseService().query(Order)
        if nameText:
            query = query.join(DatabaseSoldProduct).filter(
                DatabaseSoldProduct.product_name.like(f'%{nameText}%'))
        if self.stopCalenderLineEdit.isEnabled():
            query = query.filter(DatabaseOrder.created_date <= stopDate)
        if self.startCalenderLineEdit.isEnabled():
            query = query.filter(startDate <= DatabaseOrder.created_date)
        query = query.order_by(desc(DatabaseOrder.created_date)).limit(limit)

        orderList = []
        for databaseOrder in query:
            order = Order.fromDatabase(databaseOrder)
            orderList.append(order)

        self.orderModel.setOrderList(orderList)
	def __init__(self, parent = None):
		super(OldReceiptDialog, self).__init__(parent)
		self.resize(800, 300)
		self.setModal(True)
		self.setWindowTitle('Sold Product')
		self.verticalLayout = QtWidgets.QVBoxLayout(self)
		self.verticalLayout.setContentsMargins(8, 4, 8, 2)
		self.verticalLayout.setSpacing(0)
		self.soldListViewWidget = SoldOrderListWidget(self)

		orderListDatabase = self.databaseService().query(Order).limit(2000).all()
		orderList = []
		for databaseOrder in orderListDatabase:
			order = Order.fromDatabase(databaseOrder)
			model = SoldProductModel()
			model.setOrder(order)
			model.setReadOnly(True)
			orderList.append(model)

		self.soldListViewWidget.setModel(orderList)

		global currentIndex
		currentIndex = len(orderList) - 1

		self.soldListViewWidget.setCurrentProductIndex(currentIndex)
		self.verticalLayout.addWidget(self.soldListViewWidget)

		self.__updateHeaderSizes()

		self.soldListViewWidget.currentIndexChanged.connect(self.__updateHeaderSizes)
		self.soldListViewWidget.soldProductLabelView.horizontalHeader().sectionResized.connect(self.__saveHeaderSizes)