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