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