| Line 22... |
Line 22... |
| 22 |
from reportlab.lib.units import inch
|
22 |
from reportlab.lib.units import inch
|
| 23 |
PAGE_HEIGHT=defaultPageSize[1]
|
23 |
PAGE_HEIGHT=defaultPageSize[1]
|
| 24 |
PAGE_WIDTH=defaultPageSize[0]
|
24 |
PAGE_WIDTH=defaultPageSize[0]
|
| 25 |
|
25 |
|
| 26 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem,\
|
26 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem,\
|
| 27 |
Alerts, Order, BatchNoGenerator
|
27 |
Alerts, Order, BatchNoGenerator, ReturnOrder
|
| 28 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
28 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
| 29 |
TransactionServiceException, TransactionStatus, OrderStatus
|
29 |
TransactionServiceException, TransactionStatus, OrderStatus
|
| 30 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
30 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 31 |
from shop2020.model.v1 import order
|
31 |
from shop2020.model.v1 import order
|
| 32 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
32 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| Line 722... |
Line 722... |
| 722 |
order.status = OrderStatus.DOA_CERT_INVALID
|
722 |
order.status = OrderStatus.DOA_CERT_INVALID
|
| 723 |
order.statusDescription = "DOA Certificate Invalid"
|
723 |
order.statusDescription = "DOA Certificate Invalid"
|
| 724 |
session.commit()
|
724 |
session.commit()
|
| 725 |
return True
|
725 |
return True
|
| 726 |
|
726 |
|
| - |
|
727 |
def reship_order(order_id):
|
| - |
|
728 |
"""
|
| - |
|
729 |
If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
|
| - |
|
730 |
1. Creates a new order for processing in the BILLED state. All billing information is saved.
|
| - |
|
731 |
2. Marks the current order as one of the final states SALES_RET_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
|
| - |
|
732 |
|
| - |
|
733 |
If the order is in DOA_CERT_VALID state, it does the following:
|
| - |
|
734 |
1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
|
| - |
|
735 |
2. Creates a return order for the warehouse executive to return the DOA material.
|
| - |
|
736 |
3. Marks the current order as the final DOA_RESHIPPED state.
|
| - |
|
737 |
|
| - |
|
738 |
Returns the id of the newly created order.
|
| - |
|
739 |
|
| - |
|
740 |
Throws an exception if the order with the given id couldn't be found.
|
| - |
|
741 |
|
| - |
|
742 |
Parameters:
|
| - |
|
743 |
- orderId
|
| - |
|
744 |
"""
|
| - |
|
745 |
order = get_order(order_id)
|
| - |
|
746 |
if order.status == OrderStatus.SALES_RET_RECEIVED:
|
| - |
|
747 |
new_order = __clone_order(order, True)
|
| - |
|
748 |
order.status = OrderStatus.SALES_RET_RESHIPPED
|
| - |
|
749 |
order.statusDescription = "Order Reshipped"
|
| - |
|
750 |
session.commit()
|
| - |
|
751 |
elif order.status == OrderStatus.DOA_CERT_INVALID:
|
| - |
|
752 |
new_order = __clone_order(order, True)
|
| - |
|
753 |
order.status = OrderStatus.DOA_INVALID_RESHIPPED
|
| - |
|
754 |
order.statusDescription = "Order Reshipped"
|
| - |
|
755 |
session.commit()
|
| - |
|
756 |
elif order.status == OrderStatus.DOA_CERT_VALID:
|
| - |
|
757 |
new_order = __clone_order(order, False)
|
| - |
|
758 |
ret_order = __create_return_order(order)
|
| - |
|
759 |
order.status = OrderStatus.DOA_RESHIPPED
|
| - |
|
760 |
order.statusDescription = "Order Reshipped"
|
| - |
|
761 |
session.commit()
|
| - |
|
762 |
else:
|
| - |
|
763 |
raise TransactionServiceException(112, "This order can't be reshipped")
|
| - |
|
764 |
|
| - |
|
765 |
order.new_order_id = new_order.id
|
| - |
|
766 |
session.commit()
|
| - |
|
767 |
|
| - |
|
768 |
return new_order.id
|
| - |
|
769 |
|
| - |
|
770 |
def refund_order(order_id):
|
| - |
|
771 |
"""
|
| - |
|
772 |
If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
|
| - |
|
773 |
1. Creates a refund request for batch processing.
|
| - |
|
774 |
2. Creates a return order for the warehouse executive to return the shipped material.
|
| - |
|
775 |
3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
|
| - |
|
776 |
|
| - |
|
777 |
If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
|
| - |
|
778 |
1. Creates a refund request for batch processing.
|
| - |
|
779 |
2. Marks the current order as the REFUNDED final state.
|
| - |
|
780 |
|
| - |
|
781 |
Returns True if it is successful.
|
| - |
|
782 |
|
| - |
|
783 |
Throws an exception if the order with the given id couldn't be found.
|
| - |
|
784 |
|
| - |
|
785 |
Parameters:
|
| - |
|
786 |
- orderId
|
| - |
|
787 |
"""
|
| - |
|
788 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
| - |
|
789 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
| - |
|
790 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
| - |
|
791 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
|
| - |
|
792 |
OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED
|
| - |
|
793 |
}
|
| - |
|
794 |
order = get_order(order_id)
|
| - |
|
795 |
if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
|
| - |
|
796 |
__create_return_order(order)
|
| - |
|
797 |
__create_refund(order)
|
| - |
|
798 |
order.status = status_transition[order.status]
|
| - |
|
799 |
order.statusDescription = "Refunded"
|
| - |
|
800 |
elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
|
| - |
|
801 |
__create_refund(order)
|
| - |
|
802 |
order.status = status_transition[order.status]
|
| - |
|
803 |
order.statusDescription = "Refunded"
|
| - |
|
804 |
else:
|
| - |
|
805 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| - |
|
806 |
|
| - |
|
807 |
session.commit()
|
| - |
|
808 |
return True
|
| - |
|
809 |
|
| - |
|
810 |
def __clone_order(order, should_copy_billing_info):
|
| - |
|
811 |
current_time = datetime.datetime.now()
|
| - |
|
812 |
new_order = Order()
|
| - |
|
813 |
new_order.customer_id = order.customer_id
|
| - |
|
814 |
new_order.customer_name = order.customer_name
|
| - |
|
815 |
new_order.customer_city = order.customer_city
|
| - |
|
816 |
new_order.customer_state = order.customer_state
|
| - |
|
817 |
new_order.customer_mobilenumber = order.customer_mobilenumber
|
| - |
|
818 |
new_order.customer_pincode = order.customer_pincode
|
| - |
|
819 |
new_order.customer_address1 = order.customer_address1
|
| - |
|
820 |
new_order.customer_address2 = order.customer_address2
|
| - |
|
821 |
new_order.customer_email = order.customer_email
|
| - |
|
822 |
new_order.total_amount = order.total_amount
|
| - |
|
823 |
new_order.total_weight = order.total_weight
|
| - |
|
824 |
new_order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
|
| - |
|
825 |
new_order.statusDescription = 'Submitted for Processing'
|
| - |
|
826 |
new_order.created_timestamp = current_time
|
| - |
|
827 |
|
| - |
|
828 |
new_order.transaction = order.transaction
|
| - |
|
829 |
|
| - |
|
830 |
for line_item in order.lineitems:
|
| - |
|
831 |
litem = LineItem()
|
| - |
|
832 |
litem.item_id = line_item.item_id
|
| - |
|
833 |
litem.productGroup = line_item.productGroup
|
| - |
|
834 |
litem.brand = line_item.brand
|
| - |
|
835 |
if line_item.model_number:
|
| - |
|
836 |
litem.model_number = line_item.model_number
|
| - |
|
837 |
if line_item.model_name:
|
| - |
|
838 |
litem.model_name = line_item.model_name
|
| - |
|
839 |
if line_item.color:
|
| - |
|
840 |
litem.color = line_item.color
|
| - |
|
841 |
if line_item.extra_info:
|
| - |
|
842 |
litem.extra_info = line_item.extra_info
|
| - |
|
843 |
litem.quantity = line_item.quantity
|
| - |
|
844 |
litem.unit_price = line_item.unit_price
|
| - |
|
845 |
litem.unit_weight = line_item.unit_weight
|
| - |
|
846 |
litem.total_price = line_item.total_price
|
| - |
|
847 |
litem.total_weight = line_item.total_weight
|
| - |
|
848 |
litem.transfer_price = line_item.transfer_price
|
| - |
|
849 |
litem.order = new_order
|
| - |
|
850 |
|
| - |
|
851 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
852 |
item_id = new_order.lineitems[0].item_id
|
| - |
|
853 |
logistics_info = logistics_client.getLogisticsInfo(new_order.customer_pincode, item_id) #TODO: We should be able to pass another flag to suggest ignoring the inventory situation.
|
| - |
|
854 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| - |
|
855 |
|
| - |
|
856 |
new_order.warehouse_id = logistics_info.warehouseId
|
| - |
|
857 |
new_order.logistics_provider_id = logistics_info.providerId
|
| - |
|
858 |
new_order.airwaybill_no = logistics_info.airway_billno
|
| - |
|
859 |
new_order.tracking_id = new_order.airwaybill_no
|
| - |
|
860 |
new_order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
| - |
|
861 |
|
| - |
|
862 |
if should_copy_billing_info:
|
| - |
|
863 |
new_order.invoice_number = order.invoice_number
|
| - |
|
864 |
new_order.billed_by = order.billed_by
|
| - |
|
865 |
new_order.warehouse_id = order.warehouse_id
|
| - |
|
866 |
new_order.accepted_timestamp = current_time
|
| - |
|
867 |
new_order.billing_timestamp = current_time
|
| - |
|
868 |
new_order.status = OrderStatus.BILLED
|
| - |
|
869 |
new_order.statusDescription = 'Order Billed'
|
| - |
|
870 |
else:
|
| - |
|
871 |
catalog_client = InventoryClient().get_client()
|
| - |
|
872 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, new_order.lineitems[0].quantity)
|
| - |
|
873 |
|
| - |
|
874 |
item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
|
| - |
|
875 |
new_order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| - |
|
876 |
|
| - |
|
877 |
return new_order
|
| - |
|
878 |
|
| - |
|
879 |
def __create_return_order(order):
|
| - |
|
880 |
ret_order = ReturnOrder()
|
| - |
|
881 |
ret_order.order_id = order.id
|
| - |
|
882 |
ret_order.jacket_number = order.jacket_number
|
| - |
|
883 |
ret_order.invoice_number = order.invoice_number
|
| - |
|
884 |
|
| - |
|
885 |
line_item = order.lineitems[0]
|
| - |
|
886 |
ret_order.item_id = line_item.item_id
|
| - |
|
887 |
ret_order.productGroup = line_item.productGroup
|
| - |
|
888 |
ret_order.brand = line_item.brand
|
| - |
|
889 |
ret_order.model_number = line_item.model_number
|
| - |
|
890 |
ret_order.model_name = line_item.model_name
|
| - |
|
891 |
ret_order.color = line_item.color
|
| - |
|
892 |
ret_order.total_price = line_item.total_price
|
| - |
|
893 |
ret_order.transfer_price = line_item.transfer_price
|
| - |
|
894 |
ret_order.created_timestamp = datetime.datetime.now()
|
| - |
|
895 |
return ret_order
|
| - |
|
896 |
|
| - |
|
897 |
def __create_refund(order):
|
| - |
|
898 |
pass
|
| - |
|
899 |
|
| 727 |
def __get_order_address(order):
|
900 |
def __get_order_address(order):
|
| 728 |
address = order.customer_name + "\n" + order.customer_address1 + "\n"
|
901 |
address = order.customer_name + "\n" + order.customer_address1 + "\n"
|
| 729 |
if order.customer_address2:
|
902 |
if order.customer_address2:
|
| 730 |
address = address + order.customer_address2 + "\n"
|
903 |
address = address + order.customer_address2 + "\n"
|
| 731 |
address = address + order.customer_city + "\n"
|
904 |
address = address + order.customer_city + "\n"
|