Subversion Repositories SmartDukaan

Rev

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

from shop2020.thriftpy.logistics.ttypes import Provider as TProvider,\
    ShipmentUpdate as TShipmentUpdate, ShipmentStatusInfo as TShipmentStatusInfo,\
    Shipment as TShipment
from shop2020.logistics.service.impl.DataService import Shipment
from shop2020.utils.Utils import to_java_date


def to_t_provider(provider):
    t_provider = TProvider()
    t_provider.id = provider.id
    t_provider.name = provider.name
    return t_provider

def to_t_shipment(shipment):
    t_shipment = TShipment()
    t_shipment.awb = shipment.awb
    t_shipment.destination = shipment.destination
    t_shipment.origin = shipment.origin
    t_shipment.recepient_address = shipment.recepient_address
    t_shipment.recepient_name = shipment.recepient_name
    t_shipment.recepient_phone = shipment.recepient_phone
    t_shipment.recepient_pincode = shipment.recepient_pincode
    t_shipment.shipment_contents = shipment.shipment_contents
    t_shipment.shipment_weight = shipment.shipment_weight
    t_shipment.timestamp = to_java_date(shipment.timestamp)
    t_shipment.warehouse_name = shipment.warehouse_name
    return t_shipment

def to_t_shipmentstatusinfo(updates):
    t_shipment_status = TShipmentStatusInfo()
    
    ret_updates = []
    for update in updates:
        ret_updates.append(to_t_shipmentupdate(update))
    
    t_shipment_status.updates = ret_updates
    
    t_shipment_status.awb = "129102"
    t_shipment_status.provider_id = 1 
    t_shipment_status.currentUpdate = to_t_shipmentupdate(update)  #last update is added right nuw
    return t_shipment_status
        
def to_t_shipmentupdate(update):
    t_update = TShipmentUpdate()
    t_update.pin =  update.pin 
    t_update.description = update.description
    t_update.timestamp = to_java_date(update.timestamp)
    return t_update