-
Notifications
You must be signed in to change notification settings - Fork 1
/
CateringProduct.py
80 lines (71 loc) · 3.2 KB
/
CateringProduct.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
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 3 21:09:00 2019
@author: L.A.B
"""
class CateringProduct:
def __init__(self, name, tipe = '', cost = 0, price = 0, liter = 0, white = 0, uni = 0, uni_n = 0, inloadf = 0):
self.name = str(name)
self.type = str(tipe)
self.cost = float(cost)
self.price = float(price)
self.liter = float(liter)
self.white = int(white)
self.uni = str(uni)
self.uni_n = int(uni_n)
try:
CateringDBManager.load(CateringDBManager.db_info['products'], name = name)
except CateringObjectNotFound:
return
else:
if inloadf:
return
else:
raise CateringExistingObject
def save(self, overwrite = False):
if not hasattr(self, 'id'):
self.id = CateringDBManager.getMaxID('PRODUCTS')
try:
CateringDBManager.load(CateringDBManager.db_info['products'], self.name)
except CateringObjectNotFound:
CateringDBManager.save(CateringDBManager.db_info['products'], self.getData())
print("Produto {n} Guardado!".format(n = self.name))
return True
else:
if overwrite:
CateringDBManager.update(CateringDBManager.db_info['products'], self.getData())
print("Produto {n} Atualizado!".format(n = self.name))
return True
else:
raise CateringExistingObject
def load(name, like = False):
try:
data = CateringDBManager.load(CateringDBManager.db_info['products'], name = name, like = like)
print(data)
except CateringObjectNotFound:
raise CateringObjectNotFound
else:
if like:
return data
else:
print(data)
obj = CateringProduct(data[1], tipe = data[2], cost = data[3], price = data[4], liter = data[5], white = data[6], uni = data[7], uni_n = data[8], inloadf = 1)
obj.id = data[0]
print("Produto {n} Carregado!".format(n = name))
return(obj)
def delete(self):
CateringDBManager.delete(CateringDBManager.db_info['products'], self.getData())
print("Produto {n} Removido!".format(n = self.name))
return True
def getData(self):
data = (self.id, self.name, self.type, self.cost, self.price, self.liter, self.white, self.uni, self.uni_n)
return data
def getItems():
return CateringProduct.items[self.type]
CateringProduct.items = {'carne' : ['prato refeição', 'garfo carne', 'faca carne'],
'peixe' : ['prato refeição', 'garfo peixe', 'faca peixe'],
'sopa' : ['prato sopa', 'colher sopa'],
'entrada' : ['prato pequeno', 'garfo pequeno', 'faca pequena', 'colher pequena'],
'sobremesa' : ['prato pequeno', 'garfo pequeno', 'faca pequena', 'colher pequena'],
'bebida' : ['copos de água', 'copos de vinho', 'copos de bar']}