Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
6467 amar.kumar 1
'''
2
Created on 03-Dec-2012
3
 
4
@author: Amar
5
'''
6
from elixir.entity import Entity
7
from elixir.fields import Field
8
from elixir.options import using_options, using_table_options
10864 manish.sha 9
from shop2020.thriftpy.purchase.ttypes import PurchaseReturn as TPurchaseReturn, PurchaseReturnInventoryType
6467 amar.kumar 10
from shop2020.utils.Utils import to_java_date
6821 amar.kumar 11
from sqlalchemy.types import Integer, Float, DateTime, Boolean, Enum
6467 amar.kumar 12
import datetime
13
 
14
class PurchaseReturn(Entity):
15
    '''
16
    classdocs
17
    '''
18
    id = Field(Integer, primary_key=True, autoincrement=True)
19
    vendorId = Field(Integer)
20
    amount = Field(Float)
21
    returnTimestamp = Field(DateTime)
22
    isSettled = Field(Boolean)
6821 amar.kumar 23
    type = Field(Enum('REAL', 'VIRTUAL'), default = 'REAL', server_default='REAL')
10864 manish.sha 24
    returnInventoryType = Field(Enum('GOOD', 'BAD'), default = 'GOOD', server_default='GOOD')
6467 amar.kumar 25
    using_options(shortnames=True)
26
    using_table_options(mysql_engine="InnoDB")
27
 
28
    def __init__(self, vendorId, amount):
29
        '''
30
        Constructor
31
        '''
32
        self.vendorId = vendorId
33
        self.amount = amount
34
        self.returnTimestamp = datetime.datetime.now()
35
        self.isSettled = False
36
 
37
    def to_thrift_object(self):
38
        t_purchaseReturn = TPurchaseReturn()
39
        t_purchaseReturn.id = self.id
40
        t_purchaseReturn.vendorId = self.vendorId
41
        t_purchaseReturn.amount = self.amount
42
        t_purchaseReturn.returnTimestamp = to_java_date(self.returnTimestamp)
43
        t_purchaseReturn.isSettled = self.isSettled
10864 manish.sha 44
        t_purchaseReturn.returnInventoryType = PurchaseReturnInventoryType._NAMES_TO_VALUES[self.returnInventoryType]
6467 amar.kumar 45
        return t_purchaseReturn