Subversion Repositories SmartDukaan

Rev

Rev 602 | Rev 621 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
103 ashish 14
 
501 rajveer 15
class BestSellers(Entity):
16
    item_id = Field(Integer, primary_key=True)
17
    priority = Field(Integer)
18
    status = Field(Integer)
19
 
94 ashish 20
class Warehouse(Entity):
122 ashish 21
    id = Field(Integer, primary_key=True, autoincrement=True)
483 rajveer 22
    location = Field(String(200))
103 ashish 23
    status = Field(Integer)
122 ashish 24
    addedOn = Field(DateTime)
483 rajveer 25
    lastCheckedOn = Field(DateTime)
26
    tinNumber = Field(String(50))
27
    pincode = Field(String(10))
28
    vendorString = Field(String(50))
94 ashish 29
    inventory = OneToMany('CurrentInventorySnapshot')
30
    inventoryHistory = OneToMany('ItemInventoryHistory')
31
 
32
    def __repr__(self):
33
        return "<warehouse>%s</warehouse>" %(self.location)
34
 
122 ashish 35
    @property
36
    def all_items(self):
37
        items = []
38
        for ci in self.inventory:
39
            items.append(ci.item)
40
        return items 
41
 
94 ashish 42
class Item(Entity):
122 ashish 43
    id = Field(Integer, primary_key=True, autoincrement=True)
483 rajveer 44
    manufacturer_name = Field(String(100))
45
    model_number = Field(String(50))
46
    model_name = Field(String(50))
609 chandransh 47
    color = Field(String(20))
483 rajveer 48
    category = Field(String(50))
49
    comments = Field(String(200))
122 ashish 50
    catalog_item_id = Field(Integer)
483 rajveer 51
    vendor_item_id = Field(String(50))
122 ashish 52
    feature_id = Field(Integer)
53
    feature_description = Field(String(200))
483 rajveer 54
    mrp = Field(Float)
55
    mop = Field(Float)
56
    sellingPrice = Field(Float)
609 chandransh 57
    dealerPrice = Field(Float)
483 rajveer 58
    weight = Field(Float)
122 ashish 59
    addedOn = Field(DateTime)
609 chandransh 60
    updatedOn = Field(DateTime)
122 ashish 61
    startDate = Field(DateTime)
62
    retireDate = Field(DateTime)
483 rajveer 63
    status = Field(Integer)
609 chandransh 64
    bestDealText = Field(String(100))
65
    bestDealValue = Field(Integer)
94 ashish 66
    currentInventory = OneToMany('CurrentInventorySnapshot')
67
    inventoryHistory = OneToMany('ItemInventoryHistory')
103 ashish 68
    iteminfo = OneToMany("ItemInfo")
69
    statusChangeLog = OneToMany("ItemChangeLog")
70
 
94 ashish 71
    def __repr__(self):
122 ashish 72
        return "<Item>%d</item>" % (self.id)
94 ashish 73
 
122 ashish 74
    @property
94 ashish 75
    def get_total_inventory(self):
76
        if self.currentInventory:
77
            i = 0
78
            for entry in self.currentInventory:
79
                i += entry.availability
80
            return i
81
 
82
        else:
83
            return 0;
103 ashish 84
 
122 ashish 85
    @property
94 ashish 86
    def get_all_warehouses(self):
87
        warehouses = []
122 ashish 88
        for ci in self.currentInventory:
89
            warehouses.append(ci.warehouse)
94 ashish 90
        return warehouses
609 chandransh 91
 
103 ashish 92
class ItemInfo(Entity):
122 ashish 93
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 94
    key = Field(String(30))
95
    value = Field(String(100))
96
    item = ManyToOne("Item")
97
 
98
    def __repr__(self):
99
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 100
 
94 ashish 101
 
102
class CurrentInventorySnapshot(Entity):
115 ashish 103
    #id = Field(Integer, primary_key=True)
483 rajveer 104
    #checkedOn = Field(DateTime, default=datetime.datetime.now())
94 ashish 105
    availibility = Field(Integer)
106
    item = ManyToOne("Item")
107
    warehouse = ManyToOne("Warehouse")
108
 
109
    def __repr__(self):
110
        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)
111
 
112
class ItemInventoryHistory(Entity):
122 ashish 113
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 114
    timestamp = Field(DateTime, default=datetime.datetime.now())
115
    availibility = Field(Integer)
116
    item = ManyToOne("Item")
117
    warehouse = ManyToOne("Warehouse")
118
 
119
    def __repr__(self):
120
        pass
103 ashish 121
 
122
class ItemChangeLog(Entity):
122 ashish 123
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 124
    old_status = Field(Integer)
125
    new_status = Field(Integer)
122 ashish 126
    timestamp = Field(DateTime, default=datetime.datetime.now())
103 ashish 127
    item = ManyToOne("Item")
94 ashish 128
 
103 ashish 129
    def __repr__(self):
130
        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 131
 
103 ashish 132
 
94 ashish 133
def initialize():
384 ashish 134
    metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
94 ashish 135
    metadata.bind.echo = True
136
    setup_all(True)
115 ashish 137
 
138
if __name__=="__main__":
139
    initialize()