Commit 84445021 authored by Robin Trioux's avatar Robin Trioux
Browse files

Refilling tab

New icons
parent 23ebb762
......@@ -66,9 +66,21 @@ class Client(metaclass=ClientSingleton):
int64 counter_id
string device_uuid
PaymentMethod payment_method
double amount
Eur amount
"""
try:
paymentMethodList = [com_pb2.UNKNOWN,
com_pb2.CASH,
com_pb2.CARD,
com_pb2.CHECK,
com_pb2.AE,
com_pb2.TRANSFER,
com_pb2.OTHER]
kwargs['payment_method'] = paymentMethodList[kwargs['payment_method']]
kwargs['amount'] = packMoney(kwargs['amount'])
print(kwargs)
print(type(kwargs['payment_method']))
print(type(kwargs['amount']))
refillingRequest = com_pb2.RefillingRequest(**kwargs)
refillingReply = self.stub.Refill(refillingRequest)
self.now = refillingReply.now
......
......@@ -12,11 +12,11 @@ import money
class Eur(Money):
def __init__(self,amount="0"):
def __init__(self,amount="0",currency='EUR'): #the currency parameter is here just to make this class compatible with money __add__ __sub__...
super().__init__(amount=amount,currency='EUR')
if isinstance(amount,float) is True:
printW("Eur should not be instancied with a float number, approximation may occure")
if 100*amount != 100*int(amount):
if self.as_tuple().exponent < -2:
printWW("Money with more than two decimals. Unforseen behavior may occure")
......@@ -34,4 +34,10 @@ class Eur(Money):
raise TypeError("multiplication is unsupported between "
"two money objects")
amount = self._amount * other
return self.__class__(amount)
\ No newline at end of file
return self.__class__(amount)
def as_tuple(self):
return self._amount.as_tuple()
def getExponent(self):
return self.as_tuple().exponent
\ No newline at end of file
......@@ -41,17 +41,17 @@ class QMainTab(QTabWidget):
super().__init__(parent)
# Initialization
self.TabCounter = QCounterTab()
self.TabStock = QRefillerTab()
self.tabCounter = QCounterTab()
self.tabRefiller= QRefillerTab()
self.TabStat = QWidget()
# Add tabs
self.addTab(self.TabCounter, "Comptoir")
self.addTab(self.tabCounter, "Comptoir")
self.addTab(self.tabRefiller, "Rechargement")
# self.addTab(self.TabStock, "Rechargements")
# self.addTab(self.TabStat, "Stats")
self.resize(1200, 800)
class QMainMenu(QMainWindow):
......@@ -60,7 +60,7 @@ class QMainMenu(QMainWindow):
super().__init__()
self.setWindowTitle("Gala.Manager.Core")
self.resize(1200, 800)
self.resize(1600, 1000)
self.setWindowIcon(QIcon("icon.ico"))
center(self)
......
......@@ -9,6 +9,8 @@ from PyQt5.QtGui import *
from QDataManager import QDataManager
from QNFCManager import QNFCManager
from QUIManager import QUIManager
from Client import Client
from QUtils import *
from QItemTree import *
......@@ -16,6 +18,7 @@ from QItemTree import *
class QAutoCompleteLineEdit(QLineEdit):
def __init__(self, parent=None):
super().__init__(parent)
......@@ -111,33 +114,4 @@ class QCounterTab(QWidget):
self.itemSelector.itemSelected[Product].connect(self.basket.addProduct)
class QNFCInfo(QWidget):
def __init__(self,parent=None):
nfcm=QNFCManager()
super().__init__(parent)
#Definition
self.mainLayout = QVBoxLayout()
self.groupBox = QGroupBox()
self.groupBoxLayout = QVBoxLayout()
self.rowInfo = QRowInfo()
self.userHistoryButton = QPushButton()
#Layout
self.groupBox.setLayout(self.groupBoxLayout)
self.groupBoxLayout.addWidget(self.rowInfo)
self.groupBoxLayout.addWidget(self.userHistoryButton)
#main layout
self.mainLayout.addWidget(self.groupBox)
self.setLayout(self.mainLayout)
#Settings
self.rowInfo.addRow("UID",nfcm.getCardUID())
self.rowInfo.addRow("Solde",Eur(0))
self.userHistoryButton.setText("Historique utilisateur")
self.groupBox.setTitle("Info utilisateur")
......@@ -162,3 +162,9 @@ class QDataManager(QObject, metaclass=QDataManagerSingleton):
def getPrice(self, product):
pass
def getCounter(self):
return self.counter
def getUID(self):
return self.uid
......@@ -15,6 +15,9 @@ class QAutoSelectLineEdit(QLineEdit):
super().focusInEvent(event)
QTimer.singleShot(0, self.selectAll)
def setText(self, string):
super().setText(str(string))
class QSuperTreeView(QTreeView):
def __init__(self, parent=None):
......
......@@ -20,7 +20,7 @@ class QNFCManager(QObject, metaclass=QNFCManagerSingleton):
readerRemoved = pyqtSignal()
def __init__(self):
super().__init__()
self.cardMonitor = CardMonitor()
self.cardObserver = QCardObserver()
self.cardMonitor.addObserver(self.cardObserver)
......@@ -32,6 +32,7 @@ class QNFCManager(QObject, metaclass=QNFCManagerSingleton):
self.cardObserver.cardInserted.connect(self.wrapperCardInserted)
self.cardObserver.cardRemoved.connect(self.wrapperCardRemoved)
def getCardUID(self):
return self.cardObserver.getCardUID()
......@@ -40,3 +41,6 @@ class QNFCManager(QObject, metaclass=QNFCManagerSingleton):
def wrapperCardRemoved(self):
self.cardRemoved.emit()
def hasCard(self):
return self.cardObserver.hasCard()
......@@ -15,87 +15,83 @@ from QItemTree import *
from Client import *
class QRefillerTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
class QAbstractPayment(QGroupBox):
class QAbstractPayement(QGroupBox):
credited = pyqtSignal(float)
credited = pyqtSignal(Eur)
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Paiement par carte de crédit")
self.warningDialog = None
self.paymentMethod = None
self.strictPositive = True
self.inputLine = QAutoSelectLineEdit()
self.credited.connect(self.clear)
def getPaymentMethod(self):
return self.paymentMethod
def credit(self):
osbserver = QCardObserver()
cardUID = osbserver.cardUID
def credit(self):
amountText = self.inputLine.text()
if self.formatValid(amountText, self.strictPositive,isCredit=True):
nfcm = QNFCManager()
if nfcm.hasCard():
amount = self.textToEur(amountText)
self.credited.emit(amount)
else:
warningDialog = QWarningDialog("Aucun utilisateur","Veuillez placer le tag nfc sur le lecteur.")
warningDialog.exec_()
currentText = self.inputLine.text()
currentText = (
currentText.replace("€", "").replace(",", ".").replace(" ", "").strip()
)
mantissas = currentText.split(".")
isFormatValid = True
def formatValid(self, text, strictPositive = True, isCredit = False):
if len(mantissas) == 2:
mantissas = mantissas[1]
if len(mantissas) <= 2:
isFormatValid = True # useless but visual
try: #can it be red as money ?
amount = self.textToEur(text)
except:
warningDialog = QWarningDialog("Format invalide","Veuillez saisir un nombre")
warningDialog.exec_()
return False
if amount.getExponent() >= -2: #Less or two digits before the comma ?
if not isCredit and amount == Eur(0): #0 is an acceptable number as long as it's not a validation
return True
elif amount > Eur(0) or not strictPositive:
return True
else:
isFormatValid = False
self.warningDialog = QMessageBox(
QMessageBox.Warning,
"Format invalide",
"Format invalide, veuillez saisir au plus deux chiffres après la virgule",
QMessageBox.Ok,
)
self.warningDialog.setWindowIcon(
self.style().standardIcon(QStyle.SP_MessageBoxWarning)
)
self.warningDialog.show()
center(self.warningDialog)
if isFormatValid is True:
try:
amount = float(currentText)
self.inputLine.setText(euro(0))
if amount > 0:
self.credited.emit(amount)
else:
self.warningDialog = QMessageBox(
QMessageBox.Warning,
"Format invalide",
"Format invalide, veuillez saisir un nombre strictement positif",
QMessageBox.Ok,
)
self.warningDialog.setWindowIcon(
self.style().standardIcon(QStyle.SP_MessageBoxWarning)
)
self.warningDialog.show()
center(self.warningDialog)
except:
self.warningDialog = QMessageBox(
QMessageBox.Warning,
"Format invalide",
"Format invalide, veuillez saisir un nombre",
QMessageBox.Ok,
)
self.warningDialog.setWindowIcon(
self.style().standardIcon(QStyle.SP_MessageBoxWarning)
)
self.warningDialog.show()
center(self.warningDialog)
class QCreditCardPayement(QAbstractPayement):
warningDialog = QWarningDialog("Format Invalide","Veuillez saisir un nombre strictement positif")
warningDialog.exec_()
return False
else:
warningDialog = QWarningDialog("Format Invalide","Veuillez saisir un nombre avec au plus deux chiffres après la virgule.")
warningDialog.exec_()
return False
def textToEur(self, text):
return Eur(text.replace("€", "").replace(",", ".").replace(" ", "").strip())
def formatInput(self):
inputLine = self.sender()
text = inputLine.text()
inputLine.blockSignals(True)
if self.formatValid(text,self.strictPositive):
amount = self.textToEur(text)
inputLine.setText(amount)
else:
inputLine.setText(Eur(0))
inputLine.blockSignals(False)
def clear(self):
self.inputLine.setText(Eur(0))
class QCreditCardPayment(QAbstractPayment):
def __init__(self, parent=None):
super().__init__(parent)
self.paymentMethod = 2
# Definitions
......@@ -105,16 +101,16 @@ class QCreditCardPayement(QAbstractPayement):
self.mainGridLayout = QGridLayout()
self.label = QLabel()
self.inputLine = QAutoSelectLineEdit()
self.okButton = QPushButton()
# Settings
self.label.setText("Credit:")
self.okButton.setText("OK")
self.inputLine.setMaximumWidth(150)
self.inputLine.setAlignment(Qt.AlignCenter)
self.inputLine.setText(euro(0))
self.inputLine.setText(Eur(0))
# Link
......@@ -127,27 +123,15 @@ class QCreditCardPayement(QAbstractPayement):
self.setLayout(self.mainVBoxLayout)
self.inputLine.editingFinished.connect(self.formatInputLine)
self.inputLine.editingFinished.connect(self.formatInput)
self.okButton.clicked.connect(self.credit)
self.inputLine.returnPressed.connect(self.credit)
def formatInputLine(self):
currentText = self.inputLine.text()
currentText = (
currentText.replace("€", "").replace(",", ".").replace(" ", "").strip()
)
self.inputLine.blockSignals(True)
try:
self.inputLine.setText(euro(currentText))
except:
self.inputLine.setText(euro(0))
self.inputLine.blockSignals(False)
self.inputLine.returnPressed.connect(self.formatInput)
class QCashPayement(QAbstractPayement):
class QCashPayment(QAbstractPayment):
def __init__(self, parent=None):
super().__init__(parent)
self.paymentMethod = 1
self.mainGridLayout = QGridLayout()
self.mainVBoxLayout = QVBoxLayout()
......@@ -159,7 +143,6 @@ class QCashPayement(QAbstractPayement):
self.setTitle("Paiement par espèce")
self.label = QLabel()
self.inputLine = QAutoSelectLineEdit()
self.okButton = QPushButton()
# Settings
......@@ -168,11 +151,11 @@ class QCashPayement(QAbstractPayement):
self.okButton.setText("OK")
self.inputLine.setMaximumWidth(150)
self.inputLine.setAlignment(Qt.AlignCenter)
self.inputLine.setText(euro(0))
self.moneyBack.setText(euro(0))
self.inputLine.setText(Eur(0))
self.moneyBack.setText(str(Eur(0)))
self.moneyBack.setAlignment(Qt.AlignCenter)
self.moneyBackLabel.setText("Argent à rendre:")
self.moneyIn.setText(euro(0))
self.moneyIn.setText(str(Eur(0)))
self.moneyIn.setAlignment(Qt.AlignCenter)
self.moneyInLabel.setText("Argent reçu:")
......@@ -192,126 +175,187 @@ class QCashPayement(QAbstractPayement):
self.setLayout(self.mainVBoxLayout)
self.inputLine.editingFinished.connect(self.formatInputLine)
self.inputLine.editingFinished.connect(self.formatInput)
self.moneyIn.editingFinished.connect(self.formatInput)
self.inputLine.returnPressed.connect(self.formatInput)
self.okButton.clicked.connect(self.credit)
self.inputLine.returnPressed.connect(self.credit)
self.inputLine.editingFinished.connect(self.updateMoneyBack)
self.moneyIn.editingFinished.connect(self.updateMoneyBack)
def formatInputLine(self):
currentText = self.inputLine.text()
def updateMoneyBack(self):
creditText = self.inputLine.text()
moneyInText = self.moneyIn.text()
#if self.formatValid(creditText) and self.formatValid(moneyInText):
try:
creditAmount = float(self.inputLine.text())
currentTextMoneyIn = self.moneyIn.text()
currentTextMoneyIn = (
currentTextMoneyIn.replace("€", "")
.replace(",", ".")
.replace(" ", "")
.strip()
)
moneyInAmount = float(currentTextMoneyIn)
self.moneyBack.setText(euro(moneyInAmount - creditAmount))
credit = self.textToEur(creditText)
except:
creditAmount = 0
currentTextMoneyIn = self.moneyIn.text()
currentTextMoneyIn = (
currentTextMoneyIn.replace("€", "")
.replace(",", ".")
.replace(" ", "")
.strip()
)
moneyInAmount = float(currentTextMoneyIn)
self.moneyBack.setText(euro(moneyInAmount - creditAmount))
currentText = (
currentText.replace("€", "").replace(",", ".").replace(" ", "").strip()
)
self.inputLine.blockSignals(True)
credit = Eur(0)
try:
self.inputLine.setText(euro(currentText))
moneyIn = self.textToEur(moneyInText)
except:
self.inputLine.setText(euro(0))
moneyIn = Eur(0)
self.moneyBack.setText(str(moneyIn - credit))
self.inputLine.blockSignals(False)
def formatMoneyIn(self):
currentText = self.moneyIn.text()
currentText = (
currentText.replace("€", "").replace(",", ".").replace(" ", "").strip()
)
self.moneyIn.blockSignals(True)
try:
self.MoneyIn.setText(euro(currentText))
except:
self.moneyIn.setText(euro(0))
self.moneyIn.blockSignals(False)
class QAEPayement(QCreditCardPayement):
class QAEPayment(QCreditCardPayment):
def __init__(self, parent=None):
super().__init__(parent)
self.paymentMethod = 4
self.setTitle("Paiement par compte AE")
class QNFCPayement(QGroupBox):
class QNFCPayment(QGroupBox):
def __init__(self, parent=None):
super().__init__(parent)
self.paymentMethod = 5
self.setTitle("Transfert entre cartes NFC")
class QOtherPayement(QCreditCardPayement):
class QOtherPayment(QCreditCardPayment):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Singularité")
self.strictPositive = False
self.paymentMethod = 6
def credit(self):
osbserver = QCardObserver()
cardUID = osbserver.cardUID
class QCheckPayment(QCreditCardPayment):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle("Paiement par chèque")
self.strictPositive = False
self.paymentMethod = 6
currentText = self.inputLine.text()
currentText = (
currentText.replace("€", "").replace(",", ".").replace(" ", "").strip()
)
mantissas = currentText.split(".")
isFormatValid = True
class QRefillerTab(QWidget):
if len(mantissas) == 2:
mantissas = mantissas[1]
if len(mantissas) <= 2:
isFormatValid = True # useless but visual
else:
isFormatValid = False
self.warningDialog = QMessageBox(
QMessageBox.Warning,
"Format invalide",
"Format invalide, veuillez saisir au plus deux chiffres après la virgule",
QMessageBox.Ok,
)
self.warningDialog.setWindowIcon(
self.style().standardIcon(QStyle.SP_MessageBoxWarning)
)
self.warningDialog.show()
center(self.warningDialog)
if isFormatValid is True:
try:
amount = float(currentText)
self.inputLine.setText(euro(0))
self.credited.emit(amount)
except:
self.warningDialog = QMessageBox(
QMessageBox.Warning,
"Format invalide",
"Format invalide, veuillez saisir un nombre",
QMessageBox.Ok,
)
self.warningDialog.setWindowIcon(
self.style().standardIcon(QStyle.SP_MessageBoxWarning)
)
self.warningDialog.show()
center(self.warningDialog)
def __init__(self, parent=None):
super().__init__(parent)
uim = QUIManager()
#Definitions
self.mainLayout = QHBoxLayout()
#Left pannel
self.paymentMethodGroupBox = QGroupBox()
self.paymentMethodLayout = QVBoxLayout()
self.cashPaymentRadio = QRadioButton()
self.cardPaymentRadio = QRadioButton()
self.checkPaymentRadio = QRadioButton()
self.aePaymentRadio = QRadioButton()
self.transfertPayementRadio = QRadioButton()
self.otherPaymentRadio = QRadioButton()
#Middle pannel
self.paymentLayout = QStackedLayout()
self.cashPayment = QCashPayment()
self.cardPayment = QCreditCardPayment()
self.checkPayment = QCheckPayment()
self.aePayment = QAEPayment()
self.transfertPayement = QNFCPayment()
self.otherPayment = QOtherPayment()
#Right Pannel
self.rightLayout = QVBoxLayout()
self.nfcInfo = QNFCInfo()
self.history = None
#layout
#Left pannel
self.paymentMethodGroupBox.setLayout(self.paymentMethodLayout)
self.paymentMethodLayout.addWidget(self.cashPaymentRadio)
self.paymentMethodLayout.addWidget(self.cardPaymentRadio)
self.paymentMethodLayout.addWidget(self.checkPaymentRadio)
self.paymentMethodLayout.addWidget(self.aePaymentRadio)
self.paymentMethodLayout.addWidget(self.transfertPayementRadio)
self.paymentMethodLayout.addWidget(self.otherPaymentRadio)
#midpannel
self.paymentLayout.addWidget(self.cashPayment)
self.paymentLayout.addWidget(self.cardPayment)
self.paymentLayout.addWidget(self.checkPayment)
self.paymentLayout.addWidget(self.aePayment)
self.paymentLayout.addWidget(self.transfertPayement)
self.paymentLayout.addWidget(self.otherPayment)
#Settings