Subversion Repositories SmartDukaan

Rev

Rev 746 | Rev 870 | 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
635 rajveer 9
from sqlalchemy.types import Integer, Binary
94 ashish 10
from elixir.relationships import OneToMany, ManyToOne
11
import datetime
746 rajveer 12
import elixir
94 ashish 13
 
501 rajveer 14
class BestSellers(Entity):
621 chandransh 15
    manufacturer_name = Field(String(100), primary_key=True)
16
    model_number = Field(String(50), primary_key=True)
17
    color = Field(String(20), primary_key=True)
18
    rank = Field(Integer)
19
    using_options(shortnames=True)
746 rajveer 20
    using_table_options(mysql_engine="InnoDB")
501 rajveer 21
 
94 ashish 22
class Warehouse(Entity):
122 ashish 23
    id = Field(Integer, primary_key=True, autoincrement=True)
759 chandransh 24
    displayName = Field(String(50))
483 rajveer 25
    location = Field(String(200))
103 ashish 26
    status = Field(Integer)
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))
94 ashish 32
    inventory = OneToMany('CurrentInventorySnapshot')
33
    inventoryHistory = OneToMany('ItemInventoryHistory')
643 chandransh 34
    logisticsLocation = Field(Integer)
746 rajveer 35
    using_options(shortnames=True)
36
    using_table_options(mysql_engine="InnoDB")
94 ashish 37
 
38
    def __repr__(self):
39
        return "<warehouse>%s</warehouse>" %(self.location)
40
 
122 ashish 41
    @property
42
    def all_items(self):
43
        items = []
44
        for ci in self.inventory:
45
            items.append(ci.item)
46
        return items 
626 chandransh 47
 
48
class EntityIDGenerator(Entity):
49
    id=Field(Integer, primary_key=True)
50
    using_options(shortnames=True)
746 rajveer 51
    using_table_options(mysql_engine="InnoDB")
122 ashish 52
 
94 ashish 53
class Item(Entity):
122 ashish 54
    id = Field(Integer, primary_key=True, autoincrement=True)
483 rajveer 55
    manufacturer_name = Field(String(100))
56
    model_number = Field(String(50))
57
    model_name = Field(String(50))
609 chandransh 58
    color = Field(String(20))
626 chandransh 59
    category = Field(Integer)
483 rajveer 60
    comments = Field(String(200))
122 ashish 61
    catalog_item_id = Field(Integer)
483 rajveer 62
    vendor_item_id = Field(String(50))
122 ashish 63
    feature_id = Field(Integer)
64
    feature_description = Field(String(200))
483 rajveer 65
    mrp = Field(Float)
66
    mop = Field(Float)
67
    sellingPrice = Field(Float)
609 chandransh 68
    dealerPrice = Field(Float)
724 chandransh 69
    transfer_price = Field(Float)
483 rajveer 70
    weight = Field(Float)
122 ashish 71
    addedOn = Field(DateTime)
609 chandransh 72
    updatedOn = Field(DateTime)
122 ashish 73
    startDate = Field(DateTime)
74
    retireDate = Field(DateTime)
483 rajveer 75
    status = Field(Integer)
609 chandransh 76
    bestDealText = Field(String(100))
630 chandransh 77
    bestDealValue = Field(Float)
621 chandransh 78
    bestSellingRank = Field(Integer)
94 ashish 79
    currentInventory = OneToMany('CurrentInventorySnapshot')
80
    inventoryHistory = OneToMany('ItemInventoryHistory')
103 ashish 81
    iteminfo = OneToMany("ItemInfo")
82
    statusChangeLog = OneToMany("ItemChangeLog")
724 chandransh 83
    hotspotCategory = Field(String(50))
746 rajveer 84
    using_options(shortnames=True)
85
    using_table_options(mysql_engine="InnoDB")
103 ashish 86
 
94 ashish 87
    def __repr__(self):
122 ashish 88
        return "<Item>%d</item>" % (self.id)
94 ashish 89
 
122 ashish 90
    @property
94 ashish 91
    def get_total_inventory(self):
92
        if self.currentInventory:
93
            i = 0
94
            for entry in self.currentInventory:
95
                i += entry.availability
96
            return i
97
 
98
        else:
99
            return 0;
103 ashish 100
 
122 ashish 101
    @property
94 ashish 102
    def get_all_warehouses(self):
103
        warehouses = []
122 ashish 104
        for ci in self.currentInventory:
105
            warehouses.append(ci.warehouse)
94 ashish 106
        return warehouses
609 chandransh 107
 
103 ashish 108
class ItemInfo(Entity):
122 ashish 109
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 110
    key = Field(String(30))
111
    value = Field(String(100))
112
    item = ManyToOne("Item")
746 rajveer 113
    using_options(shortnames=True)
114
    using_table_options(mysql_engine="InnoDB")
103 ashish 115
 
116
    def __repr__(self):
117
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 118
 
94 ashish 119
 
120
class CurrentInventorySnapshot(Entity):
115 ashish 121
    #id = Field(Integer, primary_key=True)
483 rajveer 122
    #checkedOn = Field(DateTime, default=datetime.datetime.now())
94 ashish 123
    availibility = Field(Integer)
124
    item = ManyToOne("Item")
125
    warehouse = ManyToOne("Warehouse")
746 rajveer 126
    using_options(shortnames=True)
127
    using_table_options(mysql_engine="InnoDB")
94 ashish 128
 
129
    def __repr__(self):
130
        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)
131
 
132
class ItemInventoryHistory(Entity):
122 ashish 133
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 134
    timestamp = Field(DateTime, default=datetime.datetime.now())
135
    availibility = Field(Integer)
136
    item = ManyToOne("Item")
137
    warehouse = ManyToOne("Warehouse")
746 rajveer 138
    using_options(shortnames=True)
139
    using_table_options(mysql_engine="InnoDB")
94 ashish 140
 
141
    def __repr__(self):
142
        pass
103 ashish 143
 
144
class ItemChangeLog(Entity):
122 ashish 145
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 146
    old_status = Field(Integer)
147
    new_status = Field(Integer)
122 ashish 148
    timestamp = Field(DateTime, default=datetime.datetime.now())
103 ashish 149
    item = ManyToOne("Item")
746 rajveer 150
    using_options(shortnames=True)
151
    using_table_options(mysql_engine="InnoDB")
94 ashish 152
 
103 ashish 153
    def __repr__(self):
154
        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 155
 
635 rajveer 156
class Category(Entity):
157
    id = Field(Integer, primary_key=True, autoincrement=True)
158
    object = Field(Binary)
746 rajveer 159
    using_options(shortnames=True)
160
    using_table_options(mysql_engine="InnoDB")
161
 
94 ashish 162
def initialize():
746 rajveer 163
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
164
    metadata.bind = 'mysql://root:shop2020@localhost/catalog'
94 ashish 165
    metadata.bind.echo = True
166
    setup_all(True)
115 ashish 167
 
168
if __name__=="__main__":
169
    initialize()