| Line 19... |
Line 19... |
| 19 |
|
19 |
|
| 20 |
from reportlab.pdfgen.canvas import Canvas
|
20 |
from reportlab.pdfgen.canvas import Canvas
|
| 21 |
from reportlab.rl_config import defaultPageSize
|
21 |
from reportlab.rl_config import defaultPageSize
|
| 22 |
from reportlab.lib.units import inch
|
22 |
from reportlab.lib.units import inch
|
| 23 |
from shop2020.clients.PaymentClient import PaymentClient
|
23 |
from shop2020.clients.PaymentClient import PaymentClient
|
| 24 |
PAGE_HEIGHT=defaultPageSize[1]
|
24 |
from shop2020.thriftpy.warehouse.ttypes import PurchaseOrder, LineItem as POLineItem
|
| 25 |
PAGE_WIDTH=defaultPageSize[0]
|
- |
|
| 26 |
|
25 |
|
| 27 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
26 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 28 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem,\
|
27 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem,\
|
| 29 |
Alerts, Order, BatchNoGenerator, InvoiceIDGenerator
|
28 |
Alerts, Order, BatchNoGenerator, InvoiceIDGenerator
|
| 30 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
29 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
| Line 34... |
Line 33... |
| 34 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
33 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 35 |
from shop2020.clients.InventoryClient import InventoryClient
|
34 |
from shop2020.clients.InventoryClient import InventoryClient
|
| 36 |
from shop2020.clients.UserClient import UserClient
|
35 |
from shop2020.clients.UserClient import UserClient
|
| 37 |
from shop2020.clients.HelperClient import HelperClient
|
36 |
from shop2020.clients.HelperClient import HelperClient
|
| 38 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
37 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| - |
|
38 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
| - |
|
39 |
|
| - |
|
40 |
PAGE_HEIGHT=defaultPageSize[1]
|
| - |
|
41 |
PAGE_WIDTH=defaultPageSize[0]
|
| 39 |
|
42 |
|
| 40 |
def get_new_transaction():
|
43 |
def get_new_transaction():
|
| 41 |
transaction = Transaction()
|
44 |
transaction = Transaction()
|
| 42 |
transaction.createdOn = datetime.datetime.now()
|
45 |
transaction.createdOn = datetime.datetime.now()
|
| 43 |
transaction.status = TransactionStatus.INIT
|
46 |
transaction.status = TransactionStatus.INIT
|
| Line 1008... |
Line 1011... |
| 1008 |
raise TransactionServiceException(116, "No return order found for the given order id")
|
1011 |
raise TransactionServiceException(116, "No return order found for the given order id")
|
| 1009 |
ret_order.processedStatus = True
|
1012 |
ret_order.processedStatus = True
|
| 1010 |
ret_order.processedAt = datetime.datetime.now()
|
1013 |
ret_order.processedAt = datetime.datetime.now()
|
| 1011 |
session.commit()
|
1014 |
session.commit()
|
| 1012 |
|
1015 |
|
| - |
|
1016 |
def create_purchase_order(warehouseId):
|
| - |
|
1017 |
if not warehouseId:
|
| - |
|
1018 |
raise TransactionServiceException(101, "bad warehouse id")
|
| - |
|
1019 |
|
| - |
|
1020 |
query = Order.query.filter_by(warehouse_id=warehouseId)
|
| - |
|
1021 |
query = query.filter_by(status=OrderStatus.SUBMITTED_FOR_PROCESSING)
|
| - |
|
1022 |
query = query.filter_by(purchase_order_id=None)
|
| - |
|
1023 |
query = query.order_by(Order.created_timestamp)
|
| - |
|
1024 |
pending_orders = query.all()
|
| - |
|
1025 |
|
| - |
|
1026 |
if not pending_orders:
|
| - |
|
1027 |
return -1
|
| - |
|
1028 |
|
| - |
|
1029 |
inventory_client = InventoryClient().get_client()
|
| - |
|
1030 |
t_warehouse = inventory_client.getWarehouse(warehouseId)
|
| - |
|
1031 |
|
| - |
|
1032 |
t_purchase_order = PurchaseOrder()
|
| - |
|
1033 |
t_purchase_order.supplierId = t_warehouse.vendorId
|
| - |
|
1034 |
t_purchase_order.warehouseId = warehouseId
|
| - |
|
1035 |
t_purchase_order.lineitems = []
|
| - |
|
1036 |
|
| - |
|
1037 |
lineitems = {}
|
| - |
|
1038 |
|
| - |
|
1039 |
for order in pending_orders:
|
| - |
|
1040 |
for lineitem in order.lineitems:
|
| - |
|
1041 |
item_id = lineitem.item_id
|
| - |
|
1042 |
if lineitems.has_key(item_id):
|
| - |
|
1043 |
lineitems[item_id].quantity = lineitems[item_id].quantity + lineitem.quantity
|
| - |
|
1044 |
else:
|
| - |
|
1045 |
t_po_lineitem = POLineItem()
|
| - |
|
1046 |
t_po_lineitem.productGroup = lineitem.productGroup
|
| - |
|
1047 |
t_po_lineitem.brand = lineitem.brand
|
| - |
|
1048 |
t_po_lineitem.modelNumber = lineitem.model_number
|
| - |
|
1049 |
t_po_lineitem.modelName = lineitem.model_name
|
| - |
|
1050 |
t_po_lineitem.color = lineitem.color
|
| - |
|
1051 |
t_po_lineitem.itemId = lineitem.item_id
|
| - |
|
1052 |
t_po_lineitem.quantity = lineitem.quantity
|
| - |
|
1053 |
t_po_lineitem.unitPrice = lineitem.transfer_price
|
| - |
|
1054 |
lineitems[item_id] = t_po_lineitem
|
| - |
|
1055 |
t_purchase_order.lineitems.append(t_po_lineitem)
|
| - |
|
1056 |
|
| - |
|
1057 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
1058 |
po_id = warehouse_client.createPurchaseOrder(t_purchase_order)
|
| - |
|
1059 |
|
| - |
|
1060 |
for order in pending_orders:
|
| - |
|
1061 |
order.purchase_order_id = po_id
|
| - |
|
1062 |
session.commit()
|
| - |
|
1063 |
return po_id
|
| - |
|
1064 |
|
| 1013 |
def close_session():
|
1065 |
def close_session():
|
| 1014 |
if session.is_active:
|
1066 |
if session.is_active:
|
| 1015 |
print "session is active. closing it."
|
1067 |
print "session is active. closing it."
|
| 1016 |
session.close()
|
1068 |
session.close()
|