| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 22-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from elixir import *
|
|
|
7 |
from elixir.entity import Entity
|
|
|
8 |
from elixir.fields import Field
|
|
|
9 |
from sqlalchemy.types import Integer
|
|
|
10 |
from elixir.relationships import OneToMany, ManyToOne
|
|
|
11 |
import datetime
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
class Category(Entity):
|
|
|
15 |
'''
|
|
|
16 |
This class represents the catalog.
|
|
|
17 |
'''
|
|
|
18 |
# id = Field(Integer)
|
|
|
19 |
name = Field(String(30))
|
|
|
20 |
isRoot = Field(Integer)
|
|
|
21 |
addedOn = Field(DateTime)
|
|
|
22 |
items = OneToMany('Item')
|
|
|
23 |
children = OneToMany('Category', inverse='parent')
|
|
|
24 |
parent = ManyToOne('Category', inverse='children')
|
|
|
25 |
|
|
|
26 |
def __repr__(self):
|
|
|
27 |
return "<id>%id </id>"%(self.id)
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
class Vendor(Entity):
|
|
|
31 |
id = Field(Integer)
|
|
|
32 |
name = Field(String(30))
|
|
|
33 |
warehouses = ManyToMany('Warehouse')
|
|
|
34 |
def __repr__(self):
|
|
|
35 |
return "<Vendor>%s</Vendor>" %(self.name)
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
class Warehouse(Entity):
|
|
|
39 |
id = Field(Integer)
|
|
|
40 |
location = Field(String(20))
|
|
|
41 |
vendors = ManyToMany('Vendor')
|
|
|
42 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
43 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
44 |
|
|
|
45 |
def __repr__(self):
|
|
|
46 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
class Item(Entity):
|
|
|
50 |
id = Field(Integer)
|
|
|
51 |
name = Field(String(20))
|
|
|
52 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
53 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
54 |
category = ManyToOne("Category")
|
|
|
55 |
def __repr__(self):
|
|
|
56 |
return "<Item>%s</item>" % (self.name)
|
|
|
57 |
|
|
|
58 |
def get_total_inventory(self):
|
|
|
59 |
if self.currentInventory:
|
|
|
60 |
i = 0
|
|
|
61 |
for entry in self.currentInventory:
|
|
|
62 |
i += entry.availability
|
|
|
63 |
return i
|
|
|
64 |
|
|
|
65 |
else:
|
|
|
66 |
return 0;
|
|
|
67 |
|
|
|
68 |
def get_all_warehouses(self):
|
|
|
69 |
warehouses = []
|
|
|
70 |
for warehouse in self.currentInventory.warehouse:
|
|
|
71 |
warehouses.append(warehouse)
|
|
|
72 |
return warehouses
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
class CurrentInventorySnapshot(Entity):
|
|
|
76 |
id = Field(Integer)
|
|
|
77 |
checkedOn = Field(DateTime, default=datetime.datetime)
|
|
|
78 |
availibility = Field(Integer)
|
|
|
79 |
item = ManyToOne("Item")
|
|
|
80 |
warehouse = ManyToOne("Warehouse")
|
|
|
81 |
|
|
|
82 |
def __repr__(self):
|
|
|
83 |
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)
|
|
|
84 |
|
|
|
85 |
#===============================================================================
|
|
|
86 |
# This is just a placeholder, will be using naveen's code for this.
|
|
|
87 |
#===============================================================================
|
|
|
88 |
|
|
|
89 |
class ItemAttribs(Entity):
|
|
|
90 |
id = Field(Integer)
|
|
|
91 |
def __repr__(self):
|
|
|
92 |
pass
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
class ItemInventoryHistory(Entity):
|
|
|
96 |
id = Field(Integer)
|
|
|
97 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
98 |
availibility = Field(Integer)
|
|
|
99 |
item = ManyToOne("Item")
|
|
|
100 |
warehouse = ManyToOne("Warehouse")
|
|
|
101 |
|
|
|
102 |
def __repr__(self):
|
|
|
103 |
pass
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
def initialize():
|
|
|
107 |
metadata.bind = "sqlite:///movies.sqlite"
|
|
|
108 |
metadata.bind.echo = True
|
|
|
109 |
|
|
|
110 |
setup_all(True)
|