Subversion Repositories SmartDukaan

Rev

Rev 24111 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 22-Mar-2010

@author: ashish
'''
import datetime

from elixir import metadata, setup_all
import elixir
from elixir.entity import Entity
from elixir.fields import Field
from elixir.options import using_options, using_table_options
from elixir.relationships import OneToMany, ManyToOne
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy.types import Integer, String, DateTime, Float, Boolean, Text, Enum, BigInteger, Date


class EntityIDGenerator(Entity):
    id=Field(Integer, primary_key=True)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Item(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    product_group = Field(String(100))
    brand = Field(String(100), default='', server_default='')
    model_number = Field(String(50), default='', server_default='')
    model_name = Field(String(100), default='', server_default='')
    color = Field(String(20), default='', server_default='')
    category = Field(Integer, default=0, server_default="0")
    comments = Field(String(200))
    catalog_item_id = Field(Integer)
    feature_id = Field(Integer)
    feature_description = Field(String(200))
    mrp = Field(Float)
    sellingPrice = Field(Float)
    weight = Field(Float)
    addedOn = Field(DateTime)
    updatedOn = Field(DateTime)
    startDate = Field(DateTime)
    retireDate = Field(DateTime)
    comingSoonStartDate = Field(DateTime)
    expectedArrivalDate = Field(DateTime)
    status = Field(Integer)
    status_description = Field(String(100))
    bestDealText = Field(String(100))
    bestDealsDetailsText = Field(String(1000))
    bestDealsDetailsLink = Field(String(200))
    bestDealValue = Field(Float)
    bestSellingRank = Field(Integer)
    statusChangeLog = OneToMany("ItemChangeLog")
    defaultForEntity = Field(Boolean)
    risky = Field(Boolean)
    expectedDelay = Field(Integer)
    warranty_period = Field(Integer)
    isWarehousePreferenceSticky = Field(Boolean)
    preferredVendor = Field(Integer)
    type = Field(Enum('SERIALIZED', 'NON_SERIALIZED'), default = 'NON_SERIALIZED', server_default='NON_SERIALIZED')
    hasItemNo = Field(Boolean)
    activeOnStore = Field(Boolean)
    showSellingPrice = Field(Boolean)
    preferredInsurer = Field(Integer)
    asin = Field(String(20))
    holdInventory = Field(Integer, default=0, server_default="0")
    defaultInventory = Field(Integer, default=0, server_default="0")
    holdOverride = Field(Boolean)
    packQuantity = Field(Integer, default=1, server_default="1")
    quantityStep = Field(Integer, default=1, server_default="1")
    minimumBuyQuantity = Field(Integer, default=1, server_default="1")
    maximumBuyQuantity = Field(Integer, default=0, server_default="0")
    hsnCode = Field(String(12))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
    def __repr__(self):
        return "<Item>%d</item>" % (self.id)

class ItemVatMaster(Entity):
    itemId = Field(Integer, primary_key=True,  autoincrement=False)
    stateId = Field(Integer, primary_key=True,  autoincrement=False)
    vatPercentage = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class CategoryHsnCodes(Entity):
    categoryId = Field(Integer, primary_key=True)
    hsnCode = Field(String(12), primary_key=True)
    description = Field(String(64))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class StateGstRate(Entity):
    item_id = Field(Integer, primary_key=True)
    state_id = Field(Integer, primary_key=True)
    igst_rate = Field(Float)
    cgst_rate = Field(Float)
    sgst_rate = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class ItemChangeLog(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    old_status = Field(Integer)
    new_status = Field(Integer)
    timestamp = Field(DateTime)
    item = ManyToOne("Item")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
    def __repr__(self):
        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)    

class Category(Entity):
    id = Field(Integer, primary_key=True, autoincrement=False)
    label = Field(String(50))
    description = Field(String(200))
    parent_category_id = Field(Integer)
    display_name = Field(String(50))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class SimilarItems(Entity):
    item = ManyToOne('Item', primary_key=True)
    catalog_item_id = Field(Integer, primary_key=True, autoincrement=False)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class ProductNotification(Entity):
    item = ManyToOne('Item', primary_key=True)
    email = Field(String(100), primary_key=True, autoincrement=False)
    addedOn = Field(DateTime, primary_key=True, autoincrement=False) 
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Source(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(50))
    identifier = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class SourceItemPricing(Entity):
    source = ManyToOne('Source', primary_key=True)
    item = ManyToOne('Item', primary_key=True)
    mrp = Field(Float)
    sellingPrice = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class AuthorizationLog(Entity):
    id = Field(Integer, primary_key=True, autoincrement = True)    
    timestamp = Field(DateTime, default=datetime.datetime.now())
    item = ManyToOne('Item')
    username = Field(String(30))
    reason = Field(Text)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class VoucherItemMapping(Entity):
    voucherType = Field(Integer, primary_key=True)
    item = ManyToOne('Item', primary_key=True)
    amount = Field(Integer, default=0, server_default="0")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class CategoryVatMaster(Entity):
    categoryId = Field(Integer, primary_key=True, autoincrement=False)
    stateId = Field(Integer, primary_key=True, autoincrement=False)
    minVal = Field(Integer, primary_key=True,  autoincrement=False)
    maxVal = Field(Integer, primary_key=True,  autoincrement=False)
    vatPercent = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class CentralGstMaster(Entity):
    hsnCode = Field(String(12), primary_key=True)
    startDate = Field(DateTime, primary_key=True)
    gstPercent = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class StateGstMaster(Entity):
    hsnCode = Field(String(12), primary_key=True)
    startDate = Field(DateTime, primary_key=True)
    stateId = Field(Integer, primary_key=True, autoincrement=False)
    sgstPercent = Field(Float)
    cgstPercent = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class OOSTracker(Entity):
    itemId = Field(Integer, primary_key=True)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class EntityTag(Entity):
    tag = Field(String(100),primary_key=True)
    entityId = Field(Integer, primary_key=True, autoincrement=False)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Banner(Entity):
    bannerName = Field(String(100),primary_key=True)
    imageName = Field(String(100))
    link = Field(String(400))
    priority = Field(Integer)
    hasMap = Field(Boolean)
    bannerType = Field(Integer,primary_key=True, autoincrement=False)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class BannerMap(Entity):
    bannerName = Field(String(100))
    mapLink = Field(String(400))
    coordinates = Field(String(20))
    bannerType = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class BannerUriMapping(Entity):
    bannerName = Field(String(100))
    uri = Field(String(100))
    isActive = Field(Boolean)
    bannerType = Field(Integer)
    target = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Campaign(Entity):
    id = Field(Integer,primary_key=True)
    campaignName = Field(String(255))
    imageName = Field(String(255))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
        
class ItemInsurerMapping(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    itemId = Field(Integer)
    insurerId = Field(Integer)
    premiumType = Field(Integer)
    premiumAmount = Field(Float)
    insurerType = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Insurer(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(255))
    address = Field(String(255))
    declaredAmount = Field(BigInteger)
    creditedAmount = Field(BigInteger)
    insurerType = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class FreebieItem(Entity):
    itemId = Field(Integer, primary_key=True)
    freebieItemId = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class BrandInfo(Entity):
    name = Field(String(255), primary_key=True)
    serviceCenterLocatorUrl = Field(String(255))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class StorePricing(Entity):
    item = ManyToOne('Item', primary_key=True)
    recommendedPrice = Field(Float)
    minPrice = Field(Float)
    maxPrice = Field(Float)
    minAdvancePrice = Field(Float)
    freebieItemId = Field(Integer)
    absoluteMinPrice = Field(Float)
    bestDealText = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")    

class Amazonlisted(Entity):
    itemId = Field(Integer, primary_key=True, autoincrement=False)
    asin = Field(String(255))
    name = Field(String(255))
    brand = Field(String(255))
    model = Field(String(255))
    manufacturer_name = Field(String(255))
    part_number = Field(String(255))
    ean = Field(String(255))
    upc = Field(String(255))
    fbaPrice = Field(Float)
    fbbPrice = Field(Float)
    fbgPrice = Field(Float)
    fbdPrice = Field(Float)
    sellingPrice = Field(Float)
    isFba = Field(Boolean)
    isNonFba = Field(Boolean)
    isFbb = Field(Boolean)
    isFbg = Field(Boolean)
    isFbd = Field(Boolean)
    isInventoryOverride = Field(Boolean)
    otherCost = Field(Float, default=0.0, server_default="0.0")
    color = Field(String(255))
    category = Field(String(255))
    handlingTime = Field(Integer)
    isCustomTime = Field(Boolean)
    category_code = Field(Integer, default=0, server_default="0")
    fbbListedOn = Field(DateTime)
    mfnPriceLastUpdatedOn = Field(DateTime)
    fbaPriceLastUpdatedOn = Field(DateTime)
    fbbPriceLastUpdatedOn = Field(DateTime)
    fbgPriceLastUpdatedOn = Field(DateTime)
    fbdPriceLastUpdatedOn = Field(DateTime)
    mfnPriceLastUpdatedOnSc = Field(DateTime)
    fbaPriceLastUpdatedOnSc = Field(DateTime)
    fbbPriceLastUpdatedOnSc = Field(DateTime)
    fbgPriceLastUpdatedOnSc = Field(DateTime)
    fbdPriceLastUpdatedOnSc = Field(DateTime)
    suppressMfnPriceUpdate = Field(Boolean)
    suppressFbaPriceUpdate = Field(Boolean)
    suppressFbbPriceUpdate = Field(Boolean)
    suppressFbgPriceUpdate = Field(Boolean)
    suppressFbdPriceUpdate = Field(Boolean)
    taxCode = Field(String(255))
    fbbtaxCode = Field(String(255))
    fbgtaxCode = Field(String(255))
    fbdtaxCode = Field(String(255))
    overrrideWanlc = Field(Boolean)
    exceptionalWanlc = Field(Float)
    autoDecrement = Field(Boolean)
    autoIncrement = Field(Boolean)
    autoFavourite = Field(Boolean)
    manualFavourite = Field(Boolean)
    fbaPromoPrice = Field(Float, default=0.0, server_default="0.0")
    fbbPromoPrice = Field(Float, default=0.0, server_default="0.0")
    fbgPromoPrice = Field(Float, default=0.0, server_default="0.0")
    fbdPromoPrice = Field(Float, default=0.0, server_default="0.0")
    fbaPromoStartDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbaPromoEndDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbbPromoStartDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbbPromoEndDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbgPromoStartDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbgPromoEndDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbdPromoStartDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbdPromoEndDate = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    fbaPromotionActive = Field(Boolean)
    fbbPromotionActive = Field(Boolean)
    fbgPromotionActive = Field(Boolean)
    fbdPromotionActive = Field(Boolean)
    packagingHeight = Field(Float)
    packagingLength = Field(Float)
    packagingWidth = Field(Float)
    packagingWeight = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class PageViewEvents(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    catalogId = Field(Integer,index=True)
    url = Field(String(255),index=True)
    sellingPrice = Field(Float)
    comingSoon = Field(Boolean)
    ip = Field(String(255))
    sessionId = Field(String(255))
    eventTimestamp = Field(DateTime,index=True)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class CartEvents(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    catalogId = Field(Integer,index=True)
    itemId = Field(Integer,index=True)
    sellingPrice = Field(Float)
    inStock = Field(Boolean)
    comingSoon = Field(Boolean)
    ip = Field(String(255))
    sessionId = Field(String(255))
    eventTimestamp = Field(DateTime,index=True)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class EbayItem(Entity):
    ebayListingId = Field(String(32), primary_key=True)
    itemId = Field(Integer, primary_key=True, autoincrement = False)
    listingName = Field(String(255))
    listingPrice = Field(Float)
    listingExpiryDate = Field(DateTime)
    subsidy = Field(Float)
    defaultWarehouseId = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class SnapdealItem(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement = False)
    exceptionPrice = Field(Float)
    warehouseId = Field(Integer)
    transferPrice = Field(Float)
    sellingPrice = Field(Float)
    courierCost =  Field(Float)
    courierCostMarketplace = Field(Float)
    commission  =  Field(Float)
    serviceTax  =  Field(Float)
    updatedOn = Field(DateTime)
    maxNlc = Field(Float)
    skuAtSnapdeal = Field(String(255))
    isListedOnSnapdeal = Field(Boolean)
    suppressPriceFeed = Field(Boolean)
    suppressInventoryFeed = Field(Boolean)
    supc = Field(String(255))
    shippingTime = Field(Integer)
    priceUpdatedBy = Field(String(255))
    isVoiListed = Field(Boolean)
    voiSellingPrice = Field(Float)
    suppressVoiPriceFeed = Field(Boolean)
    voiPriceLastUpdatedOn = Field(DateTime)
    voiSkuAtSnapdeal = Field(String(255))
    minimumPossibleSpVoi = Field(Float)
    minimumPossibleTpVoi = Field(Float)
    courierCostVoi = Field(Float)
    serviceTaxVoi = Field(Float)
    transferPriceVoi = Field(Float)
    commissionVoi = Field(Float)
    courierCostMarketplaceVoi = Field(Float)
    commissionPercentageVoi = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class MarketPlaceUpdateHistory(Entity):
    id  = Field(Integer, primary_key=True, autoincrement = True)
    item_id = Field(Integer)
    source = Field(Integer)
    isListedOnSource = Field(Boolean)
    exceptionPrice = Field(Float)
    warehouseId = Field(Integer)
    transferPrice = Field(Float)
    sellingPrice = Field(Float)
    courierCost =  Field(Float)
    courierCostMarketplace = Field(Float)
    commission  =  Field(Float)
    serviceTax  =  Field(Float)
    suppressPriceFeed = Field(Boolean)
    suppressInventoryFeed = Field(Boolean)
    maxNlc = Field(Float)
    skuAtSource = Field(String(255))
    updatedOn = Field(DateTime)
    marketPlaceSerialNumber = Field(String(255))
    priceUpdatedBy = Field(String(255))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class MarketplaceItems(Entity):
    itemId = Field(Integer,primary_key=True, autoincrement = False)
    source = Field(Integer,primary_key=True, autoincrement = False)
    emiFee = Field(Float)
    courierCost = Field(Float)
    courierCostMarketplace = Field(Float)
    closingFee = Field(Float)
    returnProvision = Field(Float)
    commission = Field(Float)
    pgFee = Field(Float)
    vat = Field(Float)
    packagingCost = Field(Float)
    otherCost = Field(Float)
    serviceTax = Field(Float)
    autoIncrement = Field(Boolean)
    autoDecrement = Field(Boolean)
    manualFavourite = Field(Boolean)
    autoFavourite = Field(Boolean)
    currentSp = Field(Float)
    currentTp = Field(Float)
    minimumPossibleSp = Field(Float)
    minimumPossibleTp = Field(Float)
    maximumSellingPrice = Field(Float)
    lastCheckedTimestamp = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class ProductFeedSubmit(Entity):
    catalogItemId = Field(Integer, primary_key=True)
    stockLinkedFeed = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class MarketPlaceItemPrice(Entity):    
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    source = Field(Integer, primary_key=True, autoincrement=False)
    sellingPrice = Field(Float)
    lastUpdatedOn = Field(DateTime)
    lastUpdatedOnMarketplace = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 15:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    suppressPriceFeed = Field(Boolean)
    isListedOnSource =  Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class SourcePercentageMaster(Entity):
    source = Field(Integer, primary_key=True, autoincrement=False)
    emiFee = Field(Float)
    closingFee = Field(Float)
    returnProvision = Field(Float)
    commission = Field(Float)
    pgFee = Field(Float)
    competitorCommissionAccessory = Field(Float)
    competitorCommissionOther = Field(Float)
    serviceTax = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class SourceItemPercentage(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    source = Field(Integer, primary_key=True, autoincrement=False)
    emiFee = Field(Float)
    closingFee = Field(Float)
    returnProvision = Field(Float)
    commission = Field(Float)
    pgFee = Field(Float)
    competitorCommissionAccessory = Field(Float)
    competitorCommissionOther = Field(Float)
    serviceTax = Field(Float)
    startDate = Field(DateTime, primary_key=True, autoincrement=False)
    expiryDate = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class SourceCategoryPercentage(Entity):
    category_id = Field(Integer, primary_key=True, autoincrement=False)
    source = Field(Integer, primary_key=True, autoincrement=False)
    emiFee = Field(Float)
    closingFee = Field(Float)
    returnProvision = Field(Float)
    commission = Field(Float)
    pgFee = Field(Float)
    competitorCommissionAccessory = Field(Float)
    competitorCommissionOther = Field(Float)
    serviceTax = Field(Float)
    startDate = Field(DateTime, primary_key=True, autoincrement=False)
    expiryDate = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class MarketPlaceHistory(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    source = Field(Integer, primary_key=True, autoincrement=False)
    lowestPossibleTp = Field(Float)
    lowestPossibleSp = Field(Float)
    ourInventory = Field(Integer)
    otherInventory = Field(Integer)
    secondLowestInventory = Field(Integer)
    ourRank = Field(Integer)
    ourOfferPrice = Field(Float)
    ourSellingPrice = Field(Float)
    ourTp = Field(Float)
    ourNlc = Field(Float)
    ourRating = Field(Float)
    ourShippingTime = Field(String(10))
    competitionBasis = Field(Integer)
    competitiveCategory = Field(Integer)
    risky = Field(Boolean)
    lowestOfferPrice = Field(Float)
    lowestSellingPrice = Field(Float)
    lowestTp = Field(Float)
    lowestSellerName = Field(String(255))
    lowestSellerCode = Field(String(255))
    lowestSellerRating = Field(Float)
    lowestSellerShippingTime = Field(String(10))
    proposedSellingPrice = Field(Float)
    proposedTp = Field(Float)
    targetNlc = Field(Float)
    salesPotential = Field(Integer)
    secondLowestSellerName = Field(String(255))
    secondLowestSellerCode = Field(String(255))
    secondLowestSellingPrice = Field(Float)
    secondLowestOfferPrice = Field(Float)
    secondLowestTp = Field(Float)
    secondLowestSellerRating = Field(Float)
    secondLowestSellerShippingTime = Field(String(10))
    prefferedSellerName = Field(String(255))
    prefferedSellerCode = Field(String(255))
    prefferedSellerSellingPrice = Field(Float)
    prefferedSellerOfferPrice = Field(Float)
    prefferedSellerTp = Field(Float)
    prefferedSellerRating = Field(Float)
    prefferedSellerShippingTime = Field(String(10))
    marginIncreasedPotential = Field(Float)
    margin = Field(Float)
    competitorEnoughStock = Field(Boolean)
    ourEnoughStock = Field(Boolean)
    totalSeller = Field(Integer)
    avgSales = Field(Float)
    decision = Field(Integer)
    reason = Field(String(255))
    run = Field(Integer)
    toGroup = Field(Boolean)
    timestamp =Field(DateTime, primary_key=True, autoincrement=False)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

    
class FlipkartItem(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement = False)
    exceptionPrice = Field(Float)
    warehouseId = Field(Integer)
    commissionValue  =  Field(Float)
    serviceTaxValue  =  Field(Float)
    maxNlc = Field(Float)
    skuAtFlipkart = Field(String(255))
    isListedOnFlipkart = Field(Boolean)
    suppressPriceFeed = Field(Boolean)
    suppressInventoryFeed = Field(Boolean)
    flipkartSerialNumber = Field(String(255))
    updatedOn = Field(DateTime)
    updatedBy = Field(String(255))
    isFaListed = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
'''    
class DealTag(Entity):
    id = Field(Integer, primary_key=True, autoincrement = True)
    name = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class ItemTag(Entity): 
    itemId= Field(Integer, primary_key=True)
    tagId = Field(Integer, primary_key=True)
    startDate = Field(DateTime)
    endDate = Field(DateTime)
    status = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
'''
    
class PrivateDeals(Entity):   
    item_id = Field(Integer, primary_key=True, autoincrement = False)
    dealFreebieItemId =  Field(Integer)
    dealPrice = Field(Float)
    startDate = Field(DateTime)
    endDate = Field(DateTime)
    dealTextOption = Field(Integer)
    dealText = Field(String(500))
    isCod =  Field(Boolean)
    rank = Field(Integer)
    dealFreebieOption = Field(Integer)
    isActive = Field(Boolean)
    minLot = Field(Integer)
    lotDealPrice = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class AmazonOutOfSync(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement = False)
    mfn = Field(Boolean)
    fba = Field(Boolean)
    fbb = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class PrivateDealsPriceComparison(Entity):
    item_id= Field(Integer, primary_key=True, autoincrement=False)
    asin = Field(String(20))
    fsn = Field(String(20))
    supc = Field(String(20))
    sdPrice = Field(Float)
    fkPrice  = Field(Float)
    amazonPrice = Field(Float)
    dealPrice = Field(Float)
    saholicPrice = Field(Float)
    lastProcessedTimestamp = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class SourceReturnPercentage(Entity):
    source = Field(Integer)
    brand = Field(String(100))
    category_id = Field(Integer)
    returnProvision = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class CompetitorPricingRequest(Entity):
    requestId = Field(BigInteger, primary_key=True,autoincrement=False)
    user = Field(String(50))
    isProcessed = Field(Boolean)
    competitorPricing = OneToMany("CompetitorPricing")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class CompetitorPricing(Entity):
    item_id = Field(Integer)
    snapdealScraping = Field(Boolean)
    flipkartScraping = Field(Boolean)
    amazonScraping = Field(Boolean)
    ourSnapdealPrice = Field(Float)
    ourSnapdealOfferPrice = Field(Float)
    ourSnapdealInventory = Field(Integer)
    lowestSnapdealPrice = Field(Float)
    lowestSnapdealOfferPrice = Field(Float)
    lowestSnapdealSeller = Field(String(255))
    lowestSnapdealSellerInventory = Field(Integer)
    ourFlipkartPrice = Field(Float)
    ourFlipkartInventory = Field(Integer)
    lowestFlipkartPrice = Field(Float)
    lowestFlipkartSeller = Field(String(255))
    ourAmazonPrice = Field(Float)
    lowestAmazonPrice = Field(Float)
    lowestAmazonSeller = Field(String(255)) 
    competitorPricing = ManyToOne("CompetitorPricingRequest")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class AmazonPromotion(Entity):
    sku = Field(String(20))
    standardPrice = Field(Float)
    salePrice = Field(Float)
    subsidy = Field(Float)
    startDate = Field(DateTime)
    endDate = Field(DateTime)
    addedOn = Field(DateTime)
    updatedOnMarketplace = Field(DateTime,default = datetime.datetime.strptime('01-01-1970 00:00:00', '%d-%m-%Y %H:%M:%S'),server_default = '1970-01-01')
    promotionActive = Field(Boolean)
    stateId = Field(Integer)
    promotionType = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class AmazonScrapingHistory(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    asin = Field(String(255))
    warehouseLocation = Field(Integer, primary_key=True, autoincrement=False)
    parentCategoryId = Field(Integer)
    ourSellingPrice = Field(Float)
    promoPrice = Field(Float)
    subsidy = Field(Float)
    lowestPossibleSp = Field(Float)
    ourRank = Field(Integer)
    ourInventory = Field(Integer)
    lowestSellerName = Field(String(255))
    lowestSellerSp = Field(Float)
    lowestSellerShippingTime = Field(String(10))
    lowestSellerRating = Field(String(10))
    lowestSellerType = Field(String(20))
    secondLowestSellerName = Field(String(255))
    secondLowestSellerSp = Field(Float)
    secondLowestSellerShippingTime = Field(String(10))
    secondLowestSellerRating = Field(String(10))
    secondLowestSellerType = Field(String(20))
    thirdLowestSellerName = Field(String(255))
    thirdLowestSellerSp = Field(Float)
    thirdLowestSellerShippingTime = Field(String(10))
    thirdLowestSellerRating = Field(String(10))
    thirdLowestSellerType = Field(String(20))
    competitiveCategory = Field(Integer)
    otherCost = Field(Float)
    isLowestMfnIgnored = Field(Boolean)
    lowestMfnIgnoredOffer = Field(Float)
    isLowestMfn = Field(Boolean)
    lowestMfnOffer = Field(Float)
    isLowestFba = Field(Boolean)
    lowestFbaOffer = Field(Float)
    competitivePrice = Field(Float)
    cheapestMfnCount = Field(Boolean)
    wanlc = Field(Float)
    commission = Field(Float)
    competitorCommission = Field(Float)
    returnProvision = Field(Float)
    vatRate = Field(Float)
    courierCost = Field(Float)
    risky = Field(Boolean)
    runType = Field(Integer)
    totalSeller = Field(Integer)
    ourEnoughStock = Field(Boolean)
    marginIncreasedPotential = Field(Float)
    avgSale = Field(Float)
    multipleListings = Field(Boolean)
    isPromotion = Field(Boolean)
    proposedSp = Field(Float)
    proposedTp = Field(Float)
    targetNlc = Field(Float)
    decision = Field(Integer)
    reason = Field(String(255))
    exceptionType = Field(Integer)
    isNlcOverridden = Field(Boolean)
    packagingHeight = Field(Float)
    packagingLength = Field(Float)
    packagingWidth = Field(Float)
    packagingWeight = Field(Float)
    isOversized = Field(Boolean)
    timestamp =Field(DateTime, primary_key=True, autoincrement=False)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    

class ExclusiveAffiliateItemInfo(Entity):
    itemId = Field(Integer, primary_key=True, autoincrement=False)
    affiliateId = Field(Integer)
    offerText = Field(String(1023))
    offerUrl = Field(String(255))
    mOfferText = Field(String(1023))
    mOfferUrl = Field(String(255))
    affiliateSku = Field(String(255))
    affiliateUrl = Field(String(255))
    addedOn = Field(DateTime)
    updatedOn = Field(DateTime)
    isActive = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class OutboundAffiliateMaster(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class HsItem(Entity):
    hsItemId = Field(String(32), primary_key=True)
    itemId = Field(Integer, primary_key=True, autoincrement = False)
    hsProductId = Field(String(32))
    listingPrice = Field(Float)
    defaultWarehouseId = Field(Integer)
    addedTimestamp = Field(DateTime)
    addedBy = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class VoiSnapdealItemInfo(Entity):
    item_id = Field(Integer, primary_key=True, autoincrement = False)
    voiSkuAtSnapdeal = Field(String(255))
    sellingPriceSnapdeal = Field(Float)
    transferPriceSnapdeal = Field(Float)
    fixedMargin = Field(Float)
    fixedMarginPercentage = Field(Float)
    logisticCostSnapdeal = Field(Float)
    woodenPackagingCost = Field(Float)
    weightSnapdeal = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    

class BulkItemPricing(Entity):
    id = Field(Integer, primary_key=True, autoincrement = True)
    item_id = Field(Integer, index=True)
    quantity = Field(Integer)
    price = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class ItemWarrantyInfo(Entity):
    catalogItemId = Field(Integer, primary_key=True,  autoincrement=False)
    itemCondition = Field(Integer, primary_key=True, autoincrement=False)
    warrantyVal = Field(Integer)
    warrantyPeriodType = Field(String(1))  
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class CategoryWarrantyInfo(Entity):
    categoryId = Field(Integer, primary_key=True, autoincrement=False)
    brand = Field(String(100), primary_key=True)
    itemCondition = Field(Integer, primary_key=True, autoincrement=False)
    warrantyVal = Field(Integer)
    warrantyPeriodType = Field(String(1))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Tag_Listing(Entity):
    id = Field(Integer, primary_key=True, autoincrement=False)               
    item_id = Field(Integer)
    tag_id = Field(Integer)
    mrp = Field(Float)          
    selling_price = Field(Float) 
    created_by = Field(Integer)
    active = Field(Boolean)
    hot_deals = Field(Boolean)
    start_date = Field(DateTime)
    create_timestamp = Field(DateTime)
    support_price = Field(Float)
    mop = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Tag_Ranking(Entity):
    catalogItemId = Field(Integer)
    rankPoints = Field(Integer)
    feature = Field(String(512))          
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

    
    

def initialize(dbname='catalog', db_hostname="localhost", setup=True):
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
    cengine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
    metadata.bind = cengine
    metadata.bind.echo = True
    setup_all(setup)

if __name__=="__main__":
    initialize()