Subversion Repositories SmartDukaan

Rev

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