-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscountDialog.py
71 lines (58 loc) · 2.37 KB
/
DiscountDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/tmp/DiscountDialogYtNkJu.ui'
#
# Created by: PyQt5 UI code generator 5.12.3
#
# WARNING! All changes made in this file will be lost!
import pymongo
from PyQt5 import QtCore, QtGui, QtWidgets
# import main1
myClient = pymongo.MongoClient('mongodb://localhost:27017')
mydb = myClient['Billing']
mycol = mydb['Promotions']
class Ui_Dialog(object):
percent = 0
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(40, 70, 101, 51))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(150, 80, 191, 25))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(280, 250, 89, 25))
self.pushButton.setObjectName("pushButton")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(40, 150, 301, 41))
self.label_2.setObjectName("label_2")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Discount Code"))
self.pushButton.setText(_translate("Dialog", "Apply"))
self.label_2.setText(_translate("Dialog", ""))
self.pushButton.clicked.connect(self.buttonClick)
def buttonClick(self):
code = self.lineEdit.text()
myquery = {'Coupon': code}
mydoc = mycol.find(myquery)
try:
print(mydoc[0]['Coupon'])
print(mydoc[0]['Redeemed'])
if mydoc[0]['Redeemed'] == 'N':
print(1)
self.percent = mydoc[0]['Percent']
print(1)
mycol.update(myquery, {'Coupon': code, 'Redeemed': 'Y'})
print(1)
self.label_2.setText('Coupon Code Applied')
else:
self.label_2.setText('Coupon code is redeemed')
except:
self.label_2.setText("Code not found")
def getPercent(self):
return self.percent