Subversion Repositories SmartDukaan

Rev

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

'''
Created on 11-Sep-2012

@author: mandeep
'''
from elixir.entity import Entity
from elixir.fields import Field
from elixir.options import using_options, using_table_options
from sqlalchemy.types import Enum, Integer, DateTime, String
from elixir.relationships import ManyToOne
import datetime
from shop2020.utils.Utils import to_java_date, to_py_date
import DigitalTransaction

class BaseOrder(Entity):
    '''
    classdocs
    '''
    id = Field(Integer, primary_key=True, autoincrement=True)
    idPrefix = Field(String(8))
    transaction = ManyToOne("DigitalTransaction")
    creationTimestamp = Field(DateTime)
    totalAmount = Field(Integer)
    walletAmount = Field(Integer)
    couponAmount = Field(Integer, default=0)
    couponCode = Field(String(256))
    userId = Field(Integer)
    userEmailId = Field(String(256))
    invoiceNumber = Field(Integer)
    orderType = Field(Integer)
    refundTimestamp = Field(DateTime)
    ipAddress = Field(String(256))
    using_options(shortnames=True, inheritance='multi')
    using_table_options(mysql_engine="InnoDB")

    def __init__(self):
        '''
        Constructor
        '''

    def to_thrift_object(self, thriftObject):
        '''
        Copies attributes to thrift object
        '''
        thriftObject.totalAmount = self.totalAmount
        thriftObject.walletAmount = self.walletAmount
        thriftObject.couponAmount = self.couponAmount
        thriftObject.couponCode = self.couponCode
        thriftObject.creationTimestamp = to_java_date(self.creationTimestamp)
        thriftObject.userEmailId = self.userEmailId
        thriftObject.userId = self.userId
        thriftObject.id = self.id
        thriftObject.displayId = self.idPrefix + str(self.id)
        thriftObject.invoiceNumber = self.invoiceNumber
        thriftObject.orderType = self.orderType
        thriftObject.transactionId = self.transaction.id
        thriftObject.refundTimestamp = to_java_date(self.refundTimestamp)
        thriftObject.ipAddress = self.ipAddress

    def from_thrift_object(self, thriftBaseOrder):
        self.totalAmount = thriftBaseOrder.totalAmount
        self.walletAmount = thriftBaseOrder.walletAmount
        self.creationTimestamp = datetime.datetime.now()
        self.userEmailId = thriftBaseOrder.userEmailId
        self.userId = thriftBaseOrder.userId
        self.invoiceNumber = thriftBaseOrder.invoiceNumber
        self.orderType = thriftBaseOrder.orderType
        self.couponAmount = thriftBaseOrder.couponAmount
        self.couponCode = thriftBaseOrder.couponCode
        if thriftBaseOrder.refundTimestamp:
            self.refundTimestamp = to_py_date(thriftBaseOrder.refundTimestamp)
        self.ipAddress = thriftBaseOrder.ipAddress

    def is_valid(self):
        return True