| 5944 |
mandeep.dh |
1 |
'''
|
|
|
2 |
Created on 22-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from elixir import metadata, setup_all
|
|
|
7 |
from elixir.entity import Entity
|
|
|
8 |
from elixir.fields import Field
|
|
|
9 |
from elixir.options import using_options, using_table_options
|
|
|
10 |
from elixir.relationships import OneToMany, ManyToOne
|
|
|
11 |
from sqlalchemy import create_engine
|
|
|
12 |
from sqlalchemy.types import Integer, String, DateTime, Float, Boolean, Enum
|
|
|
13 |
import datetime
|
|
|
14 |
|
|
|
15 |
class Vendor(Entity):
|
|
|
16 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
17 |
name = Field(String(50))
|
|
|
18 |
warehouses = OneToMany('Warehouse')
|
|
|
19 |
using_options(shortnames=True)
|
|
|
20 |
using_table_options(mysql_engine="InnoDB")
|
|
|
21 |
|
|
|
22 |
class Warehouse(Entity):
|
|
|
23 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
24 |
displayName = Field(String(50))
|
|
|
25 |
location = Field(String(200))
|
|
|
26 |
status = Field(Integer)
|
|
|
27 |
addedOn = Field(DateTime)
|
|
|
28 |
lastCheckedOn = Field(DateTime)
|
|
|
29 |
tinNumber = Field(String(50))
|
|
|
30 |
pincode = Field(String(10))
|
|
|
31 |
vendorString = Field(String(50))
|
|
|
32 |
badInventory = OneToMany('BadInventorySnapshot')
|
|
|
33 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
34 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
35 |
logisticsLocation = Field(Integer)
|
|
|
36 |
vendor = ManyToOne('Vendor')
|
|
|
37 |
billingType = Field(Integer)
|
|
|
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)
|
|
|
44 |
using_options(shortnames=True)
|
|
|
45 |
using_table_options(mysql_engine="InnoDB")
|
|
|
46 |
|
|
|
47 |
def __repr__(self):
|
|
|
48 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
49 |
|
|
|
50 |
class VendorItemMapping(Entity):
|
|
|
51 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
52 |
item_key = Field(String(200), primary_key=True)
|
|
|
53 |
item_id = Field(Integer)
|
|
|
54 |
using_options(shortnames=True)
|
|
|
55 |
using_table_options(mysql_engine="InnoDB")
|
|
|
56 |
|
|
|
57 |
class VendorItemPricing(Entity):
|
|
|
58 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
59 |
item_id = Field(Integer, primary_key=True)
|
|
|
60 |
mop = Field(Float)
|
|
|
61 |
dealerPrice = Field(Float)
|
|
|
62 |
transfer_price = Field(Float)
|
|
|
63 |
using_options(shortnames=True)
|
|
|
64 |
using_table_options(mysql_engine="InnoDB")
|
|
|
65 |
|
|
|
66 |
class VendorItemProcurementDelay(Entity):
|
|
|
67 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
68 |
item_id = Field(Integer, primary_key=True)
|
|
|
69 |
procurementDelay = Field(Integer)
|
|
|
70 |
using_options(shortnames=True)
|
|
|
71 |
using_table_options(mysql_engine="InnoDB")
|
|
|
72 |
|
|
|
73 |
class VendorHolidays(Entity):
|
|
|
74 |
vendor = ManyToOne('Vendor', primary_key=True)
|
|
|
75 |
holidayType = Field(Integer, primary_key=True, autoincrement=False)
|
|
|
76 |
holidayValue = Field(Integer, primary_key=True, autoincrement=False)
|
|
|
77 |
occasion = Field(String(100))
|
|
|
78 |
using_options(shortnames=True)
|
|
|
79 |
using_table_options(mysql_engine="InnoDB")
|
|
|
80 |
|
|
|
81 |
class CurrentInventorySnapshot(Entity):
|
|
|
82 |
item_id = Field(Integer, primary_key=True)
|
|
|
83 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
|
|
84 |
availability = Field(Integer)
|
|
|
85 |
reserved = Field(Integer)
|
|
|
86 |
using_options(shortnames=True)
|
|
|
87 |
using_table_options(mysql_engine="InnoDB")
|
|
|
88 |
|
|
|
89 |
class BadInventorySnapshot(Entity):
|
|
|
90 |
item_id = Field(Integer, primary_key=True)
|
|
|
91 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
|
|
92 |
availability = Field(Integer)
|
|
|
93 |
using_options(shortnames=True)
|
|
|
94 |
using_table_options(mysql_engine="InnoDB")
|
|
|
95 |
|
|
|
96 |
class SupplierInventorySnapshot(Entity):
|
|
|
97 |
item_id = Field(Integer, primary_key=True)
|
|
|
98 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
|
|
99 |
availability = Field(Integer)
|
|
|
100 |
using_options(shortnames=True)
|
|
|
101 |
using_table_options(mysql_engine="InnoDB")
|
|
|
102 |
|
|
|
103 |
class ItemInventoryHistory(Entity):
|
|
|
104 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
|
|
105 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
106 |
availability = Field(Integer)
|
|
|
107 |
item_id = Field(Integer)
|
|
|
108 |
warehouse = ManyToOne("Warehouse")
|
|
|
109 |
using_options(shortnames=True)
|
|
|
110 |
using_table_options(mysql_engine="InnoDB")
|
|
|
111 |
|
|
|
112 |
def __repr__(self):
|
|
|
113 |
pass
|
|
|
114 |
|
|
|
115 |
class MissedInventoryUpdate(Entity):
|
|
|
116 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
117 |
itemKey = Field(String(200))
|
|
|
118 |
quantity = Field(Integer)
|
|
|
119 |
warehouseId = Field(Integer)
|
|
|
120 |
isIgnored = Field(Boolean)
|
|
|
121 |
timestamp = Field(DateTime)
|
|
|
122 |
using_options(shortnames=True)
|
|
|
123 |
using_table_options(mysql_engine="InnoDB")
|
|
|
124 |
|
|
|
125 |
class ItemAvailabilityCache(Entity):
|
|
|
126 |
itemId = Field(Integer, primary_key=True, autoincrement=False)
|
|
|
127 |
warehouseId = Field(Integer)
|
|
|
128 |
expectedDelay = Field(Integer)
|
|
|
129 |
billingWarehouseId = Field(Integer)
|
|
|
130 |
sellingPrice = Field(Float)
|
|
|
131 |
totalAvailability = Field(Integer)
|
|
|
132 |
using_options(shortnames=True)
|
|
|
133 |
using_table_options(mysql_engine="InnoDB")
|
|
|
134 |
|
|
|
135 |
def initialize(dbname='inventory', db_hostname="localhost"):
|
|
|
136 |
#metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
|
|
137 |
#metadata.bind = 'mysql://root:shop2020@localhost/inventory'
|
|
|
138 |
engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
|
|
|
139 |
metadata.bind = engine
|
|
|
140 |
metadata.bind.echo = True
|
|
|
141 |
setup_all(True)
|
|
|
142 |
|
|
|
143 |
if __name__=="__main__":
|
|
|
144 |
initialize()
|