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

sync

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