Commit 93c2e264 authored by Robin Trioux's avatar Robin Trioux
Browse files

Refilling + history requests

parent e9abc9ef
...@@ -272,7 +272,7 @@ class Operation(Atom): ...@@ -272,7 +272,7 @@ class Operation(Atom):
def getLabel(self): def getLabel(self):
return self.label return self.label
def getRefounded(self, refounded): def getRefounded(self):
return self.refounded return self.refounded
def getCounterId(self): def getCounterId(self):
......
...@@ -7,7 +7,7 @@ from QUIManager import QUIManager ...@@ -7,7 +7,7 @@ from QUIManager import QUIManager
from QNFCManager import QNFCManager from QNFCManager import QNFCManager
from Client import Client from Client import Client
from Euro import Eur from Euro import Eur
from QUtils import QQuantity, QDelButton from QUtils import QQuantity, QDelButton, QWarningDialog, center
# ________/\\\___________/\\\\\\\\\_________________________________________________________________ # ________/\\\___________/\\\\\\\\\_________________________________________________________________
# _____/\\\\/\\\\______/\\\\\\\\\\\\\_______________________________________________________________ # _____/\\\\/\\\\______/\\\\\\\\\\\\\_______________________________________________________________
...@@ -136,6 +136,7 @@ class QCounter(QAtom, Counter): ...@@ -136,6 +136,7 @@ class QCounter(QAtom, Counter):
class QOperation(QAtom, Operation): class QOperation(QAtom, Operation):
def __init__(self, operation): def __init__(self, operation):
super().__init__(operation) super().__init__(operation)
...@@ -143,9 +144,10 @@ class QOperation(QAtom, Operation): ...@@ -143,9 +144,10 @@ class QOperation(QAtom, Operation):
class QBuying(QOperation, Buying): class QBuying(QOperation, Buying):
sRefounded = pyqtSignal() # The attribute "refounded" already exists sRefounded = pyqtSignal() # The attribute "refounded" already exists
def __init__(self, buying): def __init__(self, buying: Buying):
super().__init__(buying) super().__init__(buying)
self.actionDict["Rembourser"] = {"fct": self.refound, "icon": "delete"} if not buying.getRefounded():
self.actionDict["Rembourser"] = {"fct": self.refound, "icon": "delete"}
def refound(self): def refound(self):
client = Client() client = Client()
...@@ -170,9 +172,30 @@ class QBuying(QOperation, Buying): ...@@ -170,9 +172,30 @@ class QBuying(QOperation, Buying):
class QRefilling(QOperation, Refilling): class QRefilling(QOperation, Refilling):
sCancelled = pyqtSignal()
def __init__(self, refilling): def __init__(self, refilling):
super().__init__(refilling) super().__init__(refilling)
self.infoPannel = None self.infoPannel = None
if not self.getRefounded():
self.actionDict["Annuler"] = {"fct": self.cancel, "icon": "delete"}
def cancel(self):
client = Client()
nfcm = QNFCManager()
if nfcm.getCardUID() == self.getCustomerId():
reply = QMessageBox.question(
None, "Annuler transaction", "Annuler cette transaction ?", QMessageBox.Yes, QMessageBox.No
)
if reply == QMessageBox.Yes:
if client.requestCancelRefilling(refilling_id=self.getId()) is None:
printE("Error during canceling")
else:
self.sCancelled.emit()
else:
warningDialog = QWarningDialog("Mauvais utilisateur", "L'utilisateur n'est pas concerné par cette transaction", "Veuillez présenter une carte concernée par la transaction")
center(warningDialog)
warningDialog.exec()
class QDistribution(QAtom, Distribution): class QDistribution(QAtom, Distribution):
......
...@@ -130,7 +130,7 @@ class Client(metaclass=ClientSingleton): ...@@ -130,7 +130,7 @@ class Client(metaclass=ClientSingleton):
uint64 counter_id uint64 counter_id
string customer_id string customer_id
string device_uuid string device_uuid
uint64 max_history_size (0: no limit) uint64 max_history_size (0: no limit)
""" """
buyings = [] buyings = []
refillings = [] refillings = []
...@@ -164,13 +164,14 @@ class Client(metaclass=ClientSingleton): ...@@ -164,13 +164,14 @@ class Client(metaclass=ClientSingleton):
refoundBuyingRequest = com_pb2.RefoundBuyingRequest(**kwargs) refoundBuyingRequest = com_pb2.RefoundBuyingRequest(**kwargs)
refoundBuyingReply = self.stub.RefoundBuying(refoundBuyingRequest) refoundBuyingReply = self.stub.RefoundBuying(refoundBuyingRequest)
if refoundBuyingReply.status == com_pb2.RefoundBuyingReply.SUCCESS: if refoundBuyingReply.status == com_pb2.RefoundBuyingReply.SUCCESS:
self.now = unpackTime(refoundBuyingReply.now)
return True return True
else: else:
printE("Unable to refound: {}".format(refoundBuyingReply.status)) printE("Unable to refound: {}".format(refoundBuyingReply.status))
return None return None
except RpcError: except RpcError:
printE("RPC: Unable to get product list") printE("RPC: Unable to refound")
return None return None
def requestCounterProduct(self, **kwargs) -> [Product]: def requestCounterProduct(self, **kwargs) -> [Product]:
...@@ -236,3 +237,21 @@ class Client(metaclass=ClientSingleton): ...@@ -236,3 +237,21 @@ class Client(metaclass=ClientSingleton):
def requestTransfert(self, **kwargs): def requestTransfert(self, **kwargs):
pass pass
def requestCancelRefilling(self, **kwargs):
"""
uint64 refilling_id
"""
try:
cancelRefillingRequest = com_pb2.CancelRefillingRequest(**kwargs)
cancelRefillingReply = self.stub.CancelRefilling(cancelRefillingRequest)
if cancelRefillingReply.status == com_pb2.CancelRefillingReply.SUCCESS:
self.now = unpackTime(cancelRefillingReply.now)
return True
else:
printE("Unable to refound: {}".format(cancelRefillingReply.status))
return None
except RpcError:
printE("RPC: Unable to cancel refilling")
return None
\ No newline at end of file
...@@ -224,12 +224,12 @@ class QErrorDialog(QMessageBox): ...@@ -224,12 +224,12 @@ class QErrorDialog(QMessageBox):
# self.setWindowIcon() # self.setWindowIcon()
self.setWindowTitle(title) self.setWindowTitle(title)
self.setBaseSize(QSize(800, 600)) self.setBaseSize(QSize(800, 650))
def resizeEvent(self, event): def resizeEvent(self, event):
super().resizeEvent(event) super().resizeEvent(event)
self.setFixedWidth(600) self.setFixedWidth(600)
self.setFixedHeight(100) self.setFixedHeight(200)
class QWarningDialog(QMessageBox): class QWarningDialog(QMessageBox):
......
...@@ -77,7 +77,7 @@ class QNFCInfo(QWidget): ...@@ -77,7 +77,7 @@ class QNFCInfo(QWidget):
class QBuyingInfo(QWidget): class QBuyingInfo(QWidget):
def __init__(self, qBuying, parent=None): def __init__(self, qBuying: QBuying, parent=None):
super().__init__(parent) super().__init__(parent)
productList = qBuying.getBasketItems() productList = qBuying.getBasketItems()
# Définitons # Définitons
...@@ -146,7 +146,8 @@ class QUserInfo(QWidget): ...@@ -146,7 +146,8 @@ class QUserInfo(QWidget):
self.setLayout(self.mainLayout) self.setLayout(self.mainLayout)
# Window settings # Window settings
self.setFixedSize(500, 500) # self.setFixedSize(500, 500)
self.historyTree.treeView.expandAll()
QUtils.center(self) QUtils.center(self)
self.setWindowTitle("Information utilisateur") self.setWindowTitle("Information utilisateur")
self.setWindowIcon(uim.getWindowIcon("group")) self.setWindowIcon(uim.getWindowIcon("group"))
......
...@@ -3,9 +3,8 @@ from QTree import * ...@@ -3,9 +3,8 @@ from QTree import *
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import * from PyQt5.QtCore import *
# from Euro import * # from Euro import *
from Client import Client
# Specialized models ... # Specialized models ...
...@@ -161,7 +160,18 @@ class QRefillingHistoryModel(QTreeModel): ...@@ -161,7 +160,18 @@ class QRefillingHistoryModel(QTreeModel):
def addRefilling(self, refilling): def addRefilling(self, refilling):
qRefilling = QRefilling(refilling) qRefilling = QRefilling(refilling)
qRefilling.sCancelled.connect(self.removeRefilling)
self.insertQAtom(0, qRefilling) self.insertQAtom(0, qRefilling)
def removeRefilling(self, qRefilling: QRefilling = None):
uim = QUIManager()
if qRefilling:
pass
else:
qRefilling = self.sender()
index, item, data = self.searchQAtom(qRefilling)
self.removeRow(index.row())
uim.balanceUpdated.emit()
def data(self, index: QModelIndex, role): def data(self, index: QModelIndex, role):
...@@ -192,6 +202,31 @@ class QUserHistoryModel(QTreeModel): ...@@ -192,6 +202,31 @@ class QUserHistoryModel(QTreeModel):
self.insertQAtom(0, buyingsRootQAtom) self.insertQAtom(0, buyingsRootQAtom)
self.insertQAtom(1, refillingRootQAtom) self.insertQAtom(1, refillingRootQAtom)
self.user = user
client = Client()
buyings, refillings = client.requestHistory(type=0, customer_id=user.getId())
for buying in buyings:
qBuying = QBuying(buying)
qBuying.setTexts(["@label", "@price", str(qBuying.getRefounded())])
self.addOperation(qBuying)
# Looks like the server can't handle the case where you want both buyings AND refillings
# Hence this work around...
buyings, refillings = client.requestHistory(type=1, customer_id=user.getId())
for refilling in refillings:
qRefilling = QRefilling(refilling)
qRefilling.setTexts(["", "@amount", str(qRefilling.getRefounded())])
self.addOperation(qRefilling)
def addOperation(self, operation: QOperation):
if isinstance(operation, QBuying):
subRoot = self.index(0, 0, QModelIndex())
self.insertQAtom(0, operation, subRoot)
if isinstance(operation, QRefilling):
subRoot = self.index(1, 0, QModelIndex())
self.insertQAtom(0, operation, subRoot)
class QMultiUserModel(QTreeModel): class QMultiUserModel(QTreeModel):
......
...@@ -201,7 +201,7 @@ class QBuyingHistory(QItemTree): ...@@ -201,7 +201,7 @@ class QBuyingHistory(QItemTree):
with open(GMC_DIR / "data" / "buyingHistory", "rb") as file: # open read/write/binary file with open(GMC_DIR / "data" / "buyingHistory", "rb") as file: # open read/write/binary file
loadedBuyingHistory = pickle.load(file) loadedBuyingHistory = pickle.load(file)
return loadedBuyingHistory return loadedBuyingHistory
except: except FileNotFoundError:
return None return None
...@@ -274,7 +274,7 @@ class QUserHistory(QItemTree): ...@@ -274,7 +274,7 @@ class QUserHistory(QItemTree):
# Definition # Definition
self.mainLayout = QHBoxLayout() self.mainLayout = QHBoxLayout()
self.treeView = QSuperTreeView() self.treeView = QSuperTreeView()
self.treeModel = QUserHistoryModel(["Transaction", "Montant"], user) self.treeModel = QUserHistoryModel(["Transaction", "Montant", "Annulée"], user)
# Layout # Layout
self.treeView.setModel(self.treeModel) self.treeView.setModel(self.treeModel)
......
...@@ -380,7 +380,7 @@ class QTreeModel(QAbstractItemModel): ...@@ -380,7 +380,7 @@ class QTreeModel(QAbstractItemModel):
def insertQAtom(self, position, qAtom, parent=QModelIndex()): def insertQAtom(self, position, qAtom, parent=QModelIndex()):
self.insertRow(position, parent) self.insertRow(position, parent)
newIndex = self.index(position, 0) newIndex = self.index(position, 0, parent)
self.setData(newIndex, qAtom) self.setData(newIndex, qAtom)
def searchQAtom(self, qAtom: QAtom, parent=QModelIndex()): def searchQAtom(self, qAtom: QAtom, parent=QModelIndex()):
......
...@@ -7,5 +7,5 @@ pip install -r requirements.txt ...@@ -7,5 +7,5 @@ pip install -r requirements.txt
./manage.py protoc # Generate protobuf files ./manage.py protoc # Generate protobuf files
./manage.py setup --import 2019.json # Generate database ./manage.py setup --import 2019.json # Generate database
./manage.py runserver ./manage.py runserver -h 127.0.0.1
``` ```
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment