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

sync

parent c12d5d33
......@@ -261,3 +261,9 @@ class Counter(Atom):
def getName(self):
return self.name
def __repr__(self):
return "Counter({0}, {1})".format(self.id,self.name)
def __str__(self):
return "{0}: {1}".format(self.id,self.name)
......@@ -6,8 +6,9 @@ from grpc import RpcError
import com_pb2
import com_pb2_grpc
from google.protobuf.timestamp_pb2 import Timestamp
from google.protobuf.json_format import MessageToDict
from Atoms import *
from Console import *
class ClientSingleton(type):
_instance = {}
......@@ -20,9 +21,10 @@ class ClientSingleton(type):
class Client(metaclass=ClientSingleton):
def __init__(self):
self.serverAddress=None
self.channel = None
self.stub = None
self.serverAddress="127.0.0.1:50051"
self.channel = grpc.insecure_channel(self.serverAddress)
self.stub = com_pb2_grpc.PaymentProtocolStub(self.channel)
self.now = None
def requestBuy(self,**kwargs):
"""
......@@ -84,6 +86,19 @@ class Client(metaclass=ClientSingleton):
"""
int64 counter_id
"""
counterProduct = {}
try:
productsRequest = com_pb2.ProductsRequest(counter_id=kwargs['counter_id'])
productsReply = self.stub.Products(productsRequest)
self.now = productsReply.now
return MessageToDict(productsReply)['items']
except RpcError:
printE("Unable to get product list")
return None
# Mockup
mockupProduct1 = Product()
......@@ -115,15 +130,24 @@ class Client(metaclass=ClientSingleton):
def requestCounterList(self, **kwargs):
"""No parameters requiered"""
# Mockup
counter = Counter()
counter.id = 0
counter.name = "BAR 0"
counterList = [counter]
return counterList
counterList = []
counterListRequest = com_pb2.CounterListRequest()
try:
counterListReply = self.stub.CounterList(counterListRequest)
grpcCounterList = counterListReply.counters #get the payload
self.now = counterListReply.now #update the time
for i in grpcCounterList:
newCounter = Counter()
newCounter.setId(i.id)
newCounter.setName(i.name)
counterList.append(newCounter)
return counterList
except RpcError:
printE("Unable to get counter list")
return None
def requestTransfert(self, **kwargs):
pass
......@@ -9,5 +9,7 @@ from babel.numbers import format_currency
class Eur(Money):
def __init__(self,amount=0):
def __init__(self,amount="0"):
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")
......@@ -129,6 +129,7 @@ class QDataManager(QObject, metaclass=QDataManagerSingleton):
#counter initialisation
printI("Request counter list")
self.counterList = client.requestCounterList()
printI(self.counterList)
try:
with open("data/counter", 'r') as file:
self.counter = int(file.readline())
......@@ -142,5 +143,6 @@ class QDataManager(QObject, metaclass=QDataManagerSingleton):
file.write(str(self.counter))
printI("Request products availables for this counter")
self.productDict = client.requestCounterProduct(counter_id=self.counter)
print(self.productDict)
self.productList = parseProductDict(self.productDict)
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