-
Notifications
You must be signed in to change notification settings - Fork 0
/
modles.py
171 lines (145 loc) · 5.93 KB
/
modles.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from config import db
from datetime import datetime,timezone
class suppliers(db.Model):
id = db.Column(db.Integer, primary_key = True)
supplier_name = db.Column(db.String(50), nullable = False)
supplier_contact_num = db.Column(db.String(15), unique = True, nullable = True)
lead = db.Column(db.Integer, nullable = True)
monday = db.Column(db.Boolean)
tuesday = db.Column(db.Boolean)
wenesday = db.Column(db.Boolean)
thursday = db.Column(db.Boolean)
friday = db.Column(db.Boolean)
sataday = db.Column(db.Boolean)
sunday = db.Column(db.Boolean)
items = db.relationship('items', backref = 'suppliers')
def to_json(self):
return {
"id": self.id,
"supplierName": self.supplier_name,
"supplierContactNum": self.supplier_contact_num,
"lead": self.lead,
"monday": self.monday,
"tuesday": self.tuesday,
"wenesday": self.wenesday,
"thursday": self.thursday,
"friday": self.friday,
"sataday": self.sataday,
"sunday": self.sunday
}
def datalist(self):
return{
"id":self.id,
"main": self.supplier_name,
"supplierContactNum": self.supplier_contact_num,
"lead": self.lead,
"daysDeliver": ["monday" if (self.monday == True) else "","tuesday" if (self.tuesday ==True) else "","wenesday" if (self.wenesday==True) else "","thursday" if(self.thursday == True) else "","friday" if (self.friday ==True) else "" ,"sataday" if (self.sataday==True) else"","sunday" if(self.sunday ==True) else ""]
}
class stores(db.Model):
id = db.Column(db.Integer, primary_key = True)
store_name = db.Column(db.String(50), unique = True, nullable = False)
stock = db.relationship('stock', backref='stores')
store = db.relationship('rooms', backref = 'stores')
def to_json(self):
return{
"id": self.id,
"storeName": self.store_name
}
class rooms(db.Model):
id = db.Column(db.Integer, primary_key = True)
store_id = db.Column(db.Integer, db.ForeignKey('stores.id'),nullable = False)
room_name = db.Column(db.String(50), unique = True, nullable = False)
stock = db.relationship('stock', backref = 'rooms')
def to_json(self):
return{
"id": self.id,
"roomName": self.room_name,
"storeId": self.store_id
}
def datalist(self):
return{
"id": self.id,
"main": self.room_name,
"storeId": self.store_id
}
class catagory(db.Model):
id = db.Column(db.Integer, primary_key = True)
catagory_name = db.Column(db.String(50), unique = True, nullable = False)
items = db.relationship('items', backref = 'catagory')
def to_json(self):
return{
"id": self.id,
"catagoryName": self.catagory_name
}
class items(db.Model):
id = db.Column(db.Integer, primary_key = True)
item_name = db.Column(db.String(50), unique = True, nullable = False)
catagory_id = db.Column(db.Integer, db.ForeignKey('catagory.id'), nullable = True)
supplier_id = db.Column(db.Integer, db.ForeignKey('suppliers.id'), nullable = False)
incident = db.Column(db.Integer, nullable = False)
stock = db.relationship('stock', backref = 'items')
def to_json(self):
return{
"id": self.id,
"itemName": self.item_name,
"catagoryId": self.catagory_id,
"supplierId": self.supplier_id,
"incidet": self.incident
}
def datalist(self):
cat = ""
supp = ""
if self.catagory_id:
cat = catagory.query.filter_by(id=self.catagory_id).first().catagory_name
supp = suppliers.query.filter_by(id = self.supplier_id).first().supplier_name
return{
"id":self.id,
"main":self.item_name,
"catagoryId": self.catagory_id,
"catagory":cat ,
"supplierId": self.supplier_id,
"supplier":supp ,
"incidet": self.incident
}
class stock(db.Model):
id = db.Column(db.Integer, primary_key = True)
item_id = db.Column(db.Integer, db.ForeignKey('items.id'), nullable = False)
level = db.Column(db.Integer, nullable = False)
room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable = False)
store_id = db.Column(db.Integer, db.ForeignKey('stores.id'), nullable = False)
logs = db.relationship('logs', backref='stock')
def to_json(self):
return {
"id": self.id,
"itemId": self.item_id,
"level": self.level,
"roomId":self.room_id,
"storeId":self.store_id
}
def stock_table(self,store_id):
item_name = items.query.filter_by(id = self.item_id).first().item_name # type: ignore
room_name = rooms.query.filter_by(id = self.room_id).first().room_name # type: ignore
return{
'id': self.id,
'itemName': item_name,
'level': self.level,
'roomName': room_name,
}
class logs(db.Model):
id = db.Column(db.Integer, primary_key = True)
datetime = db.Column(db.DateTime, default=datetime.now(tz=timezone.utc))
stock_id = db.Column(db.Integer, db.ForeignKey('stock.id'),nullable = False)
amount_before = db.Column(db.Integer, nullable = False)
amount_after = db.Column(db.Integer, nullable = False)
def to_json(self):
stock_item = stock.query.filter_by(id = self.stock_id).first().item_id
item_name = items.query.filter_by(id = stock_item).first().item_name
date = self.datetime
return{
"id": self.id,
"dateTime":self.datetime,
"stockId":self.stock_id,
"itemName":item_name,
"amountBefore": self.amount_before,
"amountAfter":self.amount_after
}