| Line 2... |
Line 2... |
| 2 |
Created on 29-Mar-2010
|
2 |
Created on 29-Mar-2010
|
| 3 |
|
3 |
|
| 4 |
@author: Chandranshu
|
4 |
@author: Chandranshu
|
| 5 |
'''
|
5 |
'''
|
| 6 |
|
6 |
|
| 7 |
from datetime import date
|
7 |
from datetime import date, timedelta
|
| 8 |
from elixir import *
|
8 |
from elixir import *
|
| 9 |
from reportlab.lib.units import inch
|
9 |
from reportlab.lib.units import inch
|
| 10 |
from reportlab.pdfgen.canvas import Canvas
|
10 |
from reportlab.pdfgen.canvas import Canvas
|
| 11 |
from reportlab.rl_config import defaultPageSize
|
11 |
from reportlab.rl_config import defaultPageSize
|
| 12 |
from shop2020.clients.CatalogClient import CatalogClient
|
12 |
from shop2020.clients.CatalogClient import CatalogClient
|
| Line 23... |
Line 23... |
| 23 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
23 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 24 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
24 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
| 25 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType
|
25 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType
|
| 26 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction, \
|
26 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction, \
|
| 27 |
TransactionServiceException, TransactionStatus, OrderStatus, DelayReason, \
|
27 |
TransactionServiceException, TransactionStatus, OrderStatus, DelayReason, \
|
| 28 |
ExtraTransactionProcessingType, HotspotAction
|
28 |
ExtraTransactionProcessingType, HotspotAction, TimeoutSummary
|
| 29 |
from shop2020.thriftpy.warehouse.ttypes import PurchaseOrder, \
|
29 |
from shop2020.thriftpy.warehouse.ttypes import PurchaseOrder, \
|
| 30 |
LineItem as POLineItem, ScanType
|
30 |
LineItem as POLineItem, ScanType
|
| 31 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
31 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 32 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
32 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 33 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
33 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| Line 1705... |
Line 1705... |
| 1705 |
logging.info("Unable to accept the order")
|
1705 |
logging.info("Unable to accept the order")
|
| 1706 |
else:
|
1706 |
else:
|
| 1707 |
order_outofstock(order.id)
|
1707 |
order_outofstock(order.id)
|
| 1708 |
return
|
1708 |
return
|
| 1709 |
|
1709 |
|
| 1710 |
def mark_orders_as_po_raised(vendorId, itemId, quantity, estimate):
|
1710 |
def mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder):
|
| - |
|
1711 |
if isReminder:
|
| - |
|
1712 |
statuses = tuple([OrderStatus.LOW_INV_PO_RAISED_TIMEOUT, OrderStatus.LOW_INV_REVERSAL_TIMEOUT])
|
| - |
|
1713 |
else:
|
| - |
|
1714 |
statuses = tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW])
|
| - |
|
1715 |
|
| 1711 |
orders = Order.query.filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]))).order_by(Order.expected_shipping_time).all()
|
1716 |
orders = Order.query.filter(Order.status.in_(statuses)).order_by(Order.expected_shipping_time).all()
|
| 1712 |
for order in orders:
|
1717 |
for order in orders:
|
| 1713 |
lineitem = order.lineitems[0]
|
1718 |
lineitem = order.lineitems[0]
|
| 1714 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
1719 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
| 1715 |
if estimate > 0:
|
1720 |
if estimate > 0:
|
| 1716 |
add_delay_reason(order.id, DelayReason.OTHERS, estimate)
|
1721 |
add_delay_reason(order.id, DelayReason.OTHERS, estimate)
|
| Line 1718... |
Line 1723... |
| 1718 |
order.statusDescription = "PO Raised"
|
1723 |
order.statusDescription = "PO Raised"
|
| 1719 |
quantity = quantity - lineitem.quantity
|
1724 |
quantity = quantity - lineitem.quantity
|
| 1720 |
store_inventory_action(order, itemId, HotspotAction.PO_RAISED, estimate, lineitem.quantity)
|
1725 |
store_inventory_action(order, itemId, HotspotAction.PO_RAISED, estimate, lineitem.quantity)
|
| 1721 |
session.commit()
|
1726 |
session.commit()
|
| 1722 |
|
1727 |
|
| 1723 |
def mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate):
|
1728 |
def mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder):
|
| - |
|
1729 |
if isReminder:
|
| - |
|
1730 |
statuses = tuple([OrderStatus.LOW_INV_PO_RAISED_TIMEOUT, OrderStatus.LOW_INV_REVERSAL_TIMEOUT])
|
| - |
|
1731 |
else:
|
| - |
|
1732 |
statuses = tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW])
|
| 1724 |
orders = Order.query.filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]))).order_by(Order.expected_shipping_time).all()
|
1733 |
orders = Order.query.filter(Order.status.in_(statuses)).order_by(Order.expected_shipping_time).all()
|
| 1725 |
for order in orders:
|
1734 |
for order in orders:
|
| 1726 |
lineitem = order.lineitems[0]
|
1735 |
lineitem = order.lineitems[0]
|
| 1727 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
1736 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
| 1728 |
if estimate > 0:
|
1737 |
if estimate > 0:
|
| 1729 |
add_delay_reason(order.id, DelayReason.OTHERS, estimate)
|
1738 |
add_delay_reason(order.id, DelayReason.OTHERS, estimate)
|
| Line 1731... |
Line 1740... |
| 1731 |
order.statusDescription = "Reversal Initiated"
|
1740 |
order.statusDescription = "Reversal Initiated"
|
| 1732 |
quantity = quantity - lineitem.quantity
|
1741 |
quantity = quantity - lineitem.quantity
|
| 1733 |
store_inventory_action(order, itemId, HotspotAction.REVERSAL_INITIATED, estimate, lineitem.quantity)
|
1742 |
store_inventory_action(order, itemId, HotspotAction.REVERSAL_INITIATED, estimate, lineitem.quantity)
|
| 1734 |
session.commit()
|
1743 |
session.commit()
|
| 1735 |
|
1744 |
|
| 1736 |
def mark_orders_as_not_available(vendorId, itemId, quantity, estimate):
|
1745 |
def mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder):
|
| - |
|
1746 |
if isReminder:
|
| - |
|
1747 |
statuses = tuple([OrderStatus.LOW_INV_PO_RAISED_TIMEOUT, OrderStatus.LOW_INV_REVERSAL_TIMEOUT])
|
| - |
|
1748 |
else:
|
| - |
|
1749 |
statuses = tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW])
|
| - |
|
1750 |
|
| 1737 |
orders = Order.query.filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]))).order_by(Order.expected_shipping_time).all()
|
1751 |
orders = Order.query.filter(Order.status.in_(statuses)).order_by(Order.expected_shipping_time).all()
|
| 1738 |
for order in orders:
|
1752 |
for order in orders:
|
| 1739 |
lineitem = order.lineitems[0]
|
1753 |
lineitem = order.lineitems[0]
|
| 1740 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
1754 |
if quantity >= lineitem.quantity and itemId == lineitem.item_id:
|
| 1741 |
order.status = OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT
|
1755 |
order.status = OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT
|
| 1742 |
order.statusDescription = "Not Available"
|
1756 |
order.statusDescription = "Not Available"
|
| 1743 |
quantity = quantity - lineitem.quantity
|
1757 |
quantity = quantity - lineitem.quantity
|
| 1744 |
store_inventory_action(order, itemId, HotspotAction.NOT_AVAILABLE, estimate, lineitem.quantity)
|
1758 |
store_inventory_action(order, itemId, HotspotAction.NOT_AVAILABLE, estimate, lineitem.quantity)
|
| 1745 |
session.commit()
|
1759 |
session.commit()
|
| 1746 |
|
1760 |
|
| 1747 |
def store_inventory_action(order, itemId, hotspotAction, estimate, quantity):
|
1761 |
def store_inventory_action(order, itemId, hotspotAction, estimate, quantity):
|
| - |
|
1762 |
orderInv = OrderInventory.get_by(order_id=order.id)
|
| - |
|
1763 |
if not orderInv:
|
| 1748 |
orderInv = OrderInventory()
|
1764 |
orderInv = OrderInventory()
|
| - |
|
1765 |
orderInv.order = order
|
| 1749 |
orderInv.hotspotAction = hotspotAction
|
1766 |
orderInv.hotspotAction = hotspotAction
|
| 1750 |
orderInv.estimate = estimate
|
1767 |
orderInv.estimate = estimate
|
| 1751 |
orderInv.itemId = itemId
|
1768 |
orderInv.itemId = itemId
|
| 1752 |
orderInv.timestamp = datetime.datetime.now()
|
1769 |
orderInv.timestamp = datetime.datetime.now()
|
| 1753 |
orderInv.quantity = quantity
|
1770 |
orderInv.quantity = quantity
|
| 1754 |
orderInv.order = order
|
- |
|
| 1755 |
|
1771 |
|
| - |
|
1772 |
|
| - |
|
1773 |
def mark_orders_as_timeout(vendorId):
|
| - |
|
1774 |
ret_timeouts = {}
|
| - |
|
1775 |
orderInvs = OrderInventory.query.all()
|
| - |
|
1776 |
for orderInv in orderInvs:
|
| - |
|
1777 |
if orderInv.timestamp + timedelta(days=orderInv.estimate) < datetime.datetime.now():
|
| - |
|
1778 |
if not ret_timeouts.has_key(orderInv.itemId):
|
| - |
|
1779 |
timeout = TimeoutSummary()
|
| - |
|
1780 |
ret_timeouts[orderInv.itemId] = timeout
|
| - |
|
1781 |
else:
|
| - |
|
1782 |
timeout = ret_timeouts.get(orderInv.itemId)
|
| - |
|
1783 |
if orderInv.hotspotAction == HotspotAction.PO_RAISED and orderInv.order.status == OrderStatus.LOW_INV_PO_RAISED:
|
| - |
|
1784 |
if timeout.poRaised:
|
| - |
|
1785 |
timeout.poRaised += 1
|
| - |
|
1786 |
else:
|
| - |
|
1787 |
timeout.poRaised = 1
|
| - |
|
1788 |
|
| - |
|
1789 |
if timeout.poEstimate:
|
| - |
|
1790 |
timeout.poEstimate += orderInv.estimate
|
| - |
|
1791 |
else:
|
| - |
|
1792 |
timeout.poEstimate = orderInv.estimate
|
| - |
|
1793 |
orderInv.order.status = OrderStatus.LOW_INV_PO_RAISED_TIMEOUT
|
| - |
|
1794 |
orderInv.order.statusDescription = "PO Raised Timeout"
|
| - |
|
1795 |
elif orderInv.hotspotAction == HotspotAction.REVERSAL_INITIATED and orderInv.order.status == OrderStatus.LOW_INV_REVERSAL_IN_PROCESS:
|
| - |
|
1796 |
if timeout.reversalInitiated:
|
| - |
|
1797 |
timeout.reversalInitiated += 1
|
| - |
|
1798 |
else:
|
| - |
|
1799 |
timeout.reversalInitiated = 1
|
| - |
|
1800 |
|
| - |
|
1801 |
if timeout.reversalEstimate:
|
| - |
|
1802 |
timeout.reversalEstimate += orderInv.estimate
|
| - |
|
1803 |
else:
|
| - |
|
1804 |
timeout.reversalEstimate = orderInv.estimate
|
| - |
|
1805 |
orderInv.order.status = OrderStatus.LOW_INV_REVERSAL_TIMEOUT
|
| - |
|
1806 |
orderInv.order.statusDescription = "Reversal Initiated Timeout"
|
| - |
|
1807 |
else:
|
| - |
|
1808 |
orderInv.delete()
|
| - |
|
1809 |
session.commit()
|
| - |
|
1810 |
return ret_timeouts
|
| - |
|
1811 |
|
| - |
|
1812 |
|
| 1756 |
def close_session():
|
1813 |
def close_session():
|
| 1757 |
if session.is_active:
|
1814 |
if session.is_active:
|
| 1758 |
print "session is active. closing it."
|
1815 |
print "session is active. closing it."
|
| 1759 |
session.close()
|
1816 |
session.close()
|
| 1760 |
|
1817 |
|