Rev 104 | Rev 304 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 29-Mar-2010@author: ashish'''from shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataAccessors import create_transaction,\get_transaction, get_all_transactions, get_transactions_for_shipment_status,\get_transactions_for_customer, get_transactions_for_customer_shipment,\get_transaction_status, change_transaction_status, set_shipping_tracker_info,\change_shipping_status, set_shipping_date, set_delivery_date, get_line_items,\get_shipments, get_billings, set_billing,\get_transactions_for_shopping_cart_idfrom shop2020.model.v1.order.impl.Convertors import to_t_transaction,\to_t_lineitem, to_t_shipment, to_t_billingfrom shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderInfo,\LineItem, ShipmentInfo, BillingInfofrom shop2020.utils import OrderStatusfrom shop2020.utils.Utils import to_py_date, get_status_fdate_tdatefrom shop2020.utils.OrderStatus import get_t_status, get_c_statusclass OrderServiceHandler:def __init__(self):'''Constructor'''DataService.initialize()def createTransaction(self, transaction):"""Parameters:- transaction"""return create_transaction(transaction)def getTransaction(self, id):"""Get transaction methods.Parameters:- id"""transaction = get_transaction(id)return to_t_transaction(transaction)def getAllTransactions(self, status, from_date, to_date):"""Parameters:- status- from_date- to_date"""current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)transactions = get_all_transactions(current_status, current_from_date, current_to_date)t_transaction = []for transaction in transactions:t_transaction.append(to_t_transaction(transaction))return t_transactiondef getTransactionsForShipmentStatus(self, status, from_date, to_date):"""Parameters:- status- from_date- to_date"""current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)transactions = get_transactions_for_shipment_status(current_status, current_from_date, current_to_date)t_transaction = []for transaction in transactions:t_transaction.append(to_t_transaction(transaction))return t_transactiondef getTransactionsForCustomer(self, customerId, from_date, to_date, status):"""Parameters:- customerId- from_date- to_date- status"""current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, current_status)t_transaction = []for transaction in transactions:t_transaction.append(to_t_transaction(transaction))return t_transactiondef getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):"""Parameters:- customerId- from_date- to_date- status"""current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)transactions = get_transactions_for_customer_shipment(customerId, current_from_date, current_to_date, current_status)t_transaction = []for transaction in transactions:t_transaction.append(to_t_transaction(transaction))return t_transactiondef getTransactionsForShoppingCartId(self, shoppingCartId):"""Parameters:- shoppingCartId"""transactions = get_transactions_for_shopping_cart_id(shoppingCartId)t_transaction = []for transaction in transactions:t_transaction.append(to_t_transaction(transaction))return t_transactionpassdef getTransactionStatus(self, transactionId):"""Parameters:- transactionId"""return get_t_status(get_transaction_status(transactionId))def changeTransactionStatus(self, transactionId, status, description):"""Parameters:- transactionId- status- description"""return change_transaction_status(transactionId, get_c_status(status), description)def getOrderInfo(self, transactionId):"""Get and set individual objects in it*Parameters:- transactionId"""lineitems = get_line_items(transactionId)order_info = OrderInfo()order_info.lineitems = []for lineitem in lineitems:order_info.lineitems.append(to_t_lineitem(lineitem))order_info.id = lineitem.transaction.idreturn order_infodef getShippingInfo(self, transactionId):"""Parameters:- transactionId"""shipments = get_shipments(transactionId)shipment_info = ShipmentInfo()shipment_info.shipments = []for shipment in shipments:shipment_info.shipments.append(to_t_shipment(shipment))shipment_info.id = shipment.idreturn shipment_infodef getBillingInfo(self, transactionId):"""Parameters:- transactionId"""billings = get_billings(transactionId)billing_info = BillingInfo()billing_info.billings = []if billings:for billing in billings:billing_info.billings.append(to_t_billing(billing))billing_info.id = billing.line_item.transaction.idreturn billing_infodef addBilling(self, transactionId, billing):"""Parameters:- tranactionId- billing"""return set_billing(transactionId, billing)def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):"""Parameters:- transactionId- shippingId- trackingId- airwayBillNo- provider"""return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)def setShippingDate(self, transactionId, shippingId, timestamp):"""Parameters:- transactionId- shippingId- timestamp"""return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))def setDeliveryDate(self, transactionId, shippingid, timestamp):"""Parameters:- transactionId- shippingid- timestamp"""return set_delivery_date(transactionId, shippingid, timestamp)def changeShippingStatus(self, transactionId, shippingId, status, description):"""Parameters:- transactionId- shippingId- status- description"""return change_shipping_status(transactionId, shippingId, get_c_status(status), description)if __name__ == "__main__":order = OrderServiceHandler()t = order.getTransaction(4)print t