| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 22-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
| 4873 |
mandeep.dh |
6 |
from elixir import metadata, setup_all
|
| 94 |
ashish |
7 |
from elixir.entity import Entity
|
|
|
8 |
from elixir.fields import Field
|
| 4873 |
mandeep.dh |
9 |
from elixir.options import using_options, using_table_options
|
|
|
10 |
from elixir.relationships import OneToMany, ManyToOne, ManyToMany
|
|
|
11 |
from sqlalchemy import create_engine
|
| 4897 |
rajveer |
12 |
from sqlalchemy.types import Integer, String, DateTime, Float, Boolean, Text,\
|
|
|
13 |
Date
|
| 4873 |
mandeep.dh |
14 |
import datetime
|
|
|
15 |
import elixir
|
| 94 |
ashish |
16 |
|
| 1308 |
chandransh |
17 |
class Vendor(Entity):
|
|
|
18 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
19 |
name = Field(String(50))
|
| 4332 |
anupam.sin |
20 |
warehouses = ManyToMany('Warehouse')
|
| 1308 |
chandransh |
21 |
using_options(shortnames=True)
|
|
|
22 |
using_table_options(mysql_engine="InnoDB")
|
|
|
23 |
|
| 94 |
ashish |
24 |
class Warehouse(Entity):
|
| 122 |
ashish |
25 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 759 |
chandransh |
26 |
displayName = Field(String(50))
|
| 483 |
rajveer |
27 |
location = Field(String(200))
|
| 103 |
ashish |
28 |
status = Field(Integer)
|
| 122 |
ashish |
29 |
addedOn = Field(DateTime)
|
| 483 |
rajveer |
30 |
lastCheckedOn = Field(DateTime)
|
|
|
31 |
tinNumber = Field(String(50))
|
|
|
32 |
pincode = Field(String(10))
|
|
|
33 |
vendorString = Field(String(50))
|
| 94 |
ashish |
34 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
35 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 643 |
chandransh |
36 |
logisticsLocation = Field(Integer)
|
| 4332 |
anupam.sin |
37 |
vendors = ManyToMany('Vendor')
|
| 2841 |
chandransh |
38 |
billingType = Field(Integer)
|
| 746 |
rajveer |
39 |
using_options(shortnames=True)
|
|
|
40 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
41 |
|
|
|
42 |
def __repr__(self):
|
|
|
43 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
44 |
|
| 122 |
ashish |
45 |
@property
|
|
|
46 |
def all_items(self):
|
|
|
47 |
items = []
|
|
|
48 |
for ci in self.inventory:
|
|
|
49 |
items.append(ci.item)
|
|
|
50 |
return items
|
| 626 |
chandransh |
51 |
|
|
|
52 |
class EntityIDGenerator(Entity):
|
|
|
53 |
id=Field(Integer, primary_key=True)
|
|
|
54 |
using_options(shortnames=True)
|
| 746 |
rajveer |
55 |
using_table_options(mysql_engine="InnoDB")
|
| 122 |
ashish |
56 |
|
| 94 |
ashish |
57 |
class Item(Entity):
|
| 122 |
ashish |
58 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 963 |
chandransh |
59 |
product_group = Field(String(100))
|
|
|
60 |
brand = Field(String(100))
|
| 483 |
rajveer |
61 |
model_number = Field(String(50))
|
|
|
62 |
model_name = Field(String(50))
|
| 609 |
chandransh |
63 |
color = Field(String(20))
|
| 626 |
chandransh |
64 |
category = Field(Integer)
|
| 483 |
rajveer |
65 |
comments = Field(String(200))
|
| 122 |
ashish |
66 |
catalog_item_id = Field(Integer)
|
|
|
67 |
feature_id = Field(Integer)
|
|
|
68 |
feature_description = Field(String(200))
|
| 483 |
rajveer |
69 |
mrp = Field(Float)
|
|
|
70 |
sellingPrice = Field(Float)
|
|
|
71 |
weight = Field(Float)
|
| 122 |
ashish |
72 |
addedOn = Field(DateTime)
|
| 609 |
chandransh |
73 |
updatedOn = Field(DateTime)
|
| 122 |
ashish |
74 |
startDate = Field(DateTime)
|
|
|
75 |
retireDate = Field(DateTime)
|
| 483 |
rajveer |
76 |
status = Field(Integer)
|
| 2035 |
rajveer |
77 |
status_description = Field(String(100))
|
| 609 |
chandransh |
78 |
bestDealText = Field(String(100))
|
| 630 |
chandransh |
79 |
bestDealValue = Field(Float)
|
| 621 |
chandransh |
80 |
bestSellingRank = Field(Integer)
|
| 94 |
ashish |
81 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
82 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 103 |
ashish |
83 |
iteminfo = OneToMany("ItemInfo")
|
|
|
84 |
statusChangeLog = OneToMany("ItemChangeLog")
|
| 4762 |
phani.kuma |
85 |
preferredWarehouse = Field(Integer)
|
| 1910 |
varun.gupt |
86 |
defaultForEntity = Field(Boolean)
|
| 2251 |
ankur.sing |
87 |
risky = Field(Boolean)
|
| 3355 |
chandransh |
88 |
expectedDelay = Field(Integer)
|
| 4295 |
varun.gupt |
89 |
warranty_period = Field(Integer)
|
| 4762 |
phani.kuma |
90 |
defaultWarehouse = Field(Integer)
|
| 4406 |
anupam.sin |
91 |
isWarehousePreferenceSticky = Field(Boolean)
|
| 4506 |
phani.kuma |
92 |
preferredVendor = Field(Integer)
|
| 746 |
rajveer |
93 |
using_options(shortnames=True)
|
|
|
94 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
95 |
|
| 94 |
ashish |
96 |
def __repr__(self):
|
| 122 |
ashish |
97 |
return "<Item>%d</item>" % (self.id)
|
| 94 |
ashish |
98 |
|
| 122 |
ashish |
99 |
@property
|
| 94 |
ashish |
100 |
def get_total_inventory(self):
|
|
|
101 |
if self.currentInventory:
|
|
|
102 |
i = 0
|
|
|
103 |
for entry in self.currentInventory:
|
|
|
104 |
i += entry.availability
|
|
|
105 |
return i
|
|
|
106 |
|
|
|
107 |
else:
|
|
|
108 |
return 0;
|
| 103 |
ashish |
109 |
|
| 122 |
ashish |
110 |
@property
|
| 94 |
ashish |
111 |
def get_all_warehouses(self):
|
| 1308 |
chandransh |
112 |
return [ci.warehouse for ci in self.currentInventory]
|
|
|
113 |
|
|
|
114 |
class VendorItemMapping(Entity):
|
|
|
115 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
116 |
item_key = Field(String(200), primary_key=True)
|
|
|
117 |
item = ManyToOne('Item')
|
|
|
118 |
using_options(shortnames=True)
|
|
|
119 |
using_table_options(mysql_engine="InnoDB")
|
|
|
120 |
|
|
|
121 |
class VendorItemPricing(Entity):
|
|
|
122 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
123 |
item = ManyToOne('Item', primary_key=True)
|
|
|
124 |
mop = Field(Float)
|
|
|
125 |
dealerPrice = Field(Float)
|
|
|
126 |
transfer_price = Field(Float)
|
|
|
127 |
using_options(shortnames=True)
|
|
|
128 |
using_table_options(mysql_engine="InnoDB")
|
|
|
129 |
|
| 4897 |
rajveer |
130 |
#class VendorDetails(Entity):
|
|
|
131 |
# vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
132 |
# type = Field(Integer, primary_key=True)
|
|
|
133 |
# holiday = Field(Integer, primary_key=True)
|
|
|
134 |
# using_options(shortnames=True)
|
|
|
135 |
# using_table_options(mysql_engine="InnoDB")
|
|
|
136 |
|
|
|
137 |
class VendorItemProcurementDelay(Entity):
|
|
|
138 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
139 |
item = ManyToOne('Item', primary_key=True)
|
|
|
140 |
procurementDelay = Field(Integer)
|
|
|
141 |
using_options(shortnames=True)
|
|
|
142 |
using_table_options(mysql_engine="InnoDB")
|
|
|
143 |
|
|
|
144 |
#class VendorHolidays(Entity):
|
|
|
145 |
# vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
146 |
# date = Field(Date, primary_key=True)
|
|
|
147 |
# occasion = Field(String(100))
|
|
|
148 |
# using_options(shortnames=True)
|
|
|
149 |
# using_table_options(mysql_engine="InnoDB")
|
|
|
150 |
|
| 103 |
ashish |
151 |
class ItemInfo(Entity):
|
| 122 |
ashish |
152 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
153 |
key = Field(String(30))
|
|
|
154 |
value = Field(String(100))
|
|
|
155 |
item = ManyToOne("Item")
|
| 746 |
rajveer |
156 |
using_options(shortnames=True)
|
|
|
157 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
158 |
|
|
|
159 |
def __repr__(self):
|
|
|
160 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
161 |
|
| 94 |
ashish |
162 |
|
|
|
163 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
164 |
#id = Field(Integer, primary_key=True)
|
| 483 |
rajveer |
165 |
#checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 870 |
chandransh |
166 |
item = ManyToOne("Item", primary_key=True)
|
|
|
167 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
| 94 |
ashish |
168 |
availibility = Field(Integer)
|
| 870 |
chandransh |
169 |
reserved = Field(Integer)
|
| 746 |
rajveer |
170 |
using_options(shortnames=True)
|
|
|
171 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
172 |
|
|
|
173 |
def __repr__(self):
|
|
|
174 |
return "<current inventory><availability> %s </availability><time>%s</time><item>%s</item><warehouse>%s</warehouse></current inventory>" %(self.availibility, self.checkedOn, self.item, self.warehouse)
|
|
|
175 |
|
|
|
176 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
177 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
178 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
179 |
availibility = Field(Integer)
|
|
|
180 |
item = ManyToOne("Item")
|
|
|
181 |
warehouse = ManyToOne("Warehouse")
|
| 746 |
rajveer |
182 |
using_options(shortnames=True)
|
|
|
183 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
184 |
|
|
|
185 |
def __repr__(self):
|
|
|
186 |
pass
|
| 103 |
ashish |
187 |
|
|
|
188 |
class ItemChangeLog(Entity):
|
| 122 |
ashish |
189 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
190 |
old_status = Field(Integer)
|
|
|
191 |
new_status = Field(Integer)
|
| 1308 |
chandransh |
192 |
timestamp = Field(DateTime)
|
| 103 |
ashish |
193 |
item = ManyToOne("Item")
|
| 746 |
rajveer |
194 |
using_options(shortnames=True)
|
|
|
195 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
196 |
|
| 103 |
ashish |
197 |
def __repr__(self):
|
|
|
198 |
return "<Log><id>%d</id><item>%d</item><old_status>%d</old_status><new_status>%d</new_status></Log>" %(self.id,self.item.id, self.old_status, self.new_status)
|
| 94 |
ashish |
199 |
|
| 635 |
rajveer |
200 |
class Category(Entity):
|
| 1970 |
rajveer |
201 |
id = Field(Integer, primary_key=True, autoincrement=False)
|
|
|
202 |
label = Field(String(50))
|
|
|
203 |
description = Field(String(200))
|
|
|
204 |
parent_category_id = Field(Integer)
|
| 4762 |
phani.kuma |
205 |
display_name = Field(String(50))
|
| 746 |
rajveer |
206 |
using_options(shortnames=True)
|
|
|
207 |
using_table_options(mysql_engine="InnoDB")
|
| 1970 |
rajveer |
208 |
|
| 3008 |
rajveer |
209 |
class SimilarItems(Entity):
|
|
|
210 |
item = ManyToOne('Item', primary_key=True)
|
|
|
211 |
catalog_item_id = Field(Integer, primary_key=True, autoincrement=False)
|
|
|
212 |
using_options(shortnames=True)
|
|
|
213 |
using_table_options(mysql_engine="InnoDB")
|
|
|
214 |
|
| 3079 |
rajveer |
215 |
class ProductNotification(Entity):
|
|
|
216 |
item = ManyToOne('Item', primary_key=True)
|
|
|
217 |
email = Field(String(100), primary_key=True, autoincrement=False)
|
|
|
218 |
addedOn = Field(DateTime, primary_key=True, autoincrement=False)
|
|
|
219 |
using_options(shortnames=True)
|
|
|
220 |
using_table_options(mysql_engine="InnoDB")
|
| 3557 |
rajveer |
221 |
|
|
|
222 |
class Source(Entity):
|
|
|
223 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
224 |
name = Field(String(50))
|
|
|
225 |
identifier = Field(String(100))
|
|
|
226 |
using_options(shortnames=True)
|
|
|
227 |
using_table_options(mysql_engine="InnoDB")
|
|
|
228 |
|
|
|
229 |
class SourceItemPricing(Entity):
|
|
|
230 |
source = ManyToOne('Source', primary_key=True)
|
|
|
231 |
item = ManyToOne('Item', primary_key=True)
|
|
|
232 |
mrp = Field(Float)
|
|
|
233 |
sellingPrice = Field(Float)
|
|
|
234 |
using_options(shortnames=True)
|
|
|
235 |
using_table_options(mysql_engine="InnoDB")
|
| 746 |
rajveer |
236 |
|
| 4649 |
phani.kuma |
237 |
class AuthorizationLog(Entity):
|
|
|
238 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
|
|
239 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
240 |
item = ManyToOne('Item')
|
|
|
241 |
username = Field(String(30))
|
|
|
242 |
reason = Field(Text)
|
|
|
243 |
using_options(shortnames=True)
|
|
|
244 |
using_table_options(mysql_engine="InnoDB")
|
|
|
245 |
|
| 4873 |
mandeep.dh |
246 |
class MissedInventoryUpdate(Entity):
|
| 4748 |
mandeep.dh |
247 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
248 |
itemKey = Field(String(200))
|
| 4873 |
mandeep.dh |
249 |
quantity = Field(Integer)
|
| 4748 |
mandeep.dh |
250 |
warehouseId = Field(Integer)
|
| 4873 |
mandeep.dh |
251 |
isIgnored = Field(Boolean)
|
|
|
252 |
timestamp = Field(DateTime)
|
| 4748 |
mandeep.dh |
253 |
using_options(shortnames=True)
|
|
|
254 |
using_table_options(mysql_engine="InnoDB")
|
|
|
255 |
|
| 3187 |
rajveer |
256 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
| 746 |
rajveer |
257 |
#metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
| 1122 |
chandransh |
258 |
#metadata.bind = 'mysql://root:shop2020@localhost/catalog'
|
| 3187 |
rajveer |
259 |
engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
|
| 1122 |
chandransh |
260 |
metadata.bind = engine
|
| 94 |
ashish |
261 |
metadata.bind.echo = True
|
|
|
262 |
setup_all(True)
|
| 115 |
ashish |
263 |
|
|
|
264 |
if __name__=="__main__":
|
|
|
265 |
initialize()
|