Subversion Repositories SmartDukaan

Rev

Rev 986 | Rev 1208 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 29-Mar-2010

@author: ashish
'''

from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
    LineItem as T_LineItem, Order as T_Order, Alert as T_Alert, OrderStatus
from shop2020.utils.Utils import to_java_date
from shop2020.model.v1.order.impl.DataService import Alerts

def to_t_transaction(transaction):
    t_transaction = T_Transaction()
    t_transaction.id = transaction.id
    t_transaction.createdOn = to_java_date(transaction.createdOn)
    t_transaction.transactionStatus = transaction.status
    t_transaction.statusDescription = transaction.status_message
    t_transaction.customer_id = transaction.customer_id
    t_transaction.shoppingCartid = transaction.shopping_cart_id
    t_transaction.orders = []
    #populate orders
    for order in transaction.orders:
        t_order = to_t_order(order)
        t_transaction.orders.append(t_order)
    return t_transaction

def to_t_order(order):
    t_order = T_Order()
    t_order.id = order.id
    t_order.warehouse_id = order.warehouse_id
    t_order.logistics_provider_id = order.logistics_provider_id
    t_order.airwaybill_no = order.airwaybill_no
    t_order.tracking_id = order.tracking_id
    t_order.expected_delivery_time = to_java_date(order.expected_delivery_time)
    t_order.customer_id = order.customer_id
    t_order.customer_name = order.customer_name
    t_order.customer_mobilenumber = order.customer_mobilenumber
    t_order.customer_pincode = order.customer_pincode
    t_order.customer_address1 = order.customer_address1
    t_order.customer_address2 = order.customer_address2
    t_order.customer_city = order.customer_city
    t_order.customer_state = order.customer_state
    t_order.customer_email = order.customer_email    
    t_order.status = order.status 
    t_order.statusDescription = order.statusDescription
    t_order.total_amount = order.total_amount
    t_order.total_weight = order.total_weight
    t_order.created_timestamp = to_java_date(order.created_timestamp)
    t_order.invoice_number = order.invoice_number
    t_order.billed_by = order.billed_by
    t_order.accepted_timestamp = to_java_date(order.accepted_timestamp)
    t_order.billing_timestamp = to_java_date(order.billing_timestamp)
    t_order.shipping_timestamp = to_java_date(order.shipping_timestamp)
    t_order.delivery_timestamp = to_java_date(order.delivery_timestamp)
    t_order.jacket_number = order.jacket_number
    t_order.lineitems = []
    for lineitem in order.lineitems:
        t_lineitem = to_t_lineitem(lineitem)
        t_order.lineitems.append(t_lineitem)

    return t_order

def to_t_lineitem(lineitem):
    t_lineitem = T_LineItem()
    t_lineitem.id = lineitem.id
    t_lineitem.item_id = lineitem.item_id
    t_lineitem.productGroup = lineitem.productGroup
    t_lineitem.brand = lineitem.brand
    t_lineitem.model_number = lineitem.model_number
    t_lineitem.color = lineitem.color
    t_lineitem.model_name = lineitem.model_name
    t_lineitem.extra_info = lineitem.extra_info
    t_lineitem.unit_weight = lineitem.unit_weight
    t_lineitem.unit_price = lineitem.unit_price
    t_lineitem.total_price = lineitem.total_price
    t_lineitem.transfer_price = lineitem.transfer_price
    t_lineitem.total_weight = lineitem.total_weight 
    t_lineitem.quantity = lineitem.quantity
    return t_lineitem

def to_t_alert(alert):
    t_alert = T_Alert()
    t_alert.id = alert.id
    t_alert.comment = alert.comment
    try:
        t_alert.time_set = to_java_date(alert.time_set)
    except:
        pass
    try:
        t_alert.time_unset = to_java_date(alert.time_unset)
    except:
        pass
    t_alert.order_id = alert.order_id
    t_alert.type = alert.type
    return t_alert