Subversion Repositories SmartDukaan

Rev

Rev 5676 | Rev 5697 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5676 Rev 5684
Line 2809... Line 2809...
2809
        session.commit()
2809
        session.commit()
2810
 
2810
 
2811
def accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
2811
def accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
2812
    catalogClient = CatalogClient().get_client()
2812
    catalogClient = CatalogClient().get_client()
2813
    inventory = catalogClient.getItemInventoryByItemId(itemId)
2813
    inventory = catalogClient.getItemInventoryByItemId(itemId)
2814
    orders = Order.query.filter(Order.warehouse_id == billingWarehouseId).filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS]))).order_by(Order.expected_shipping_time).all()
2814
    orders = Order.query.filter(Order.fulfilmentWarehouseId != fulfilmentWarehouseId).filter(Order.warehouse_id == billingWarehouseId).filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.COD_VERIFICATION_PENDING, OrderStatus.ACCEPTED, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS]))).order_by(Order.expected_shipping_time).all()
2815
    for order in orders:
2815
    for order in orders:
2816
        lineitem = order.lineitems[0]
2816
        lineitem = order.lineitems[0]
2817
        if lineitem.item_id == itemId and lineitem.quantity <= quantity:
2817
        if lineitem.item_id == itemId and lineitem.quantity <= quantity:
2818
            warehouse = catalogClient.getWarehouse(order.fulfilmentWarehouseId)
2818
            warehouse = catalogClient.getWarehouse(order.fulfilmentWarehouseId)
2819
            if not warehouse.billingWarehouseId and warehouse.warehouseType == WarehouseType._VALUES_TO_NAMES[WarehouseType.THIRD_PARTY]:
2819
            if not warehouse.billingWarehouseId and warehouse.warehouseType == WarehouseType.THIRD_PARTY:
2820
                if inventory.availability.has_key(fulfilmentWarehouseId) and inventory.availability[fulfilmentWarehouseId] >= inventory.reserved[fulfilmentWarehouseId] + lineitem.quantity:
2820
                if (inventory.availability[fulfilmentWarehouseId] >= inventory.reserved[fulfilmentWarehouseId] + lineitem.quantity) and inventory.availability[order.fulfilmentWarehouseId] < inventory.reserved[order.fulfilmentWarehouseId]:
-
 
2821
                    catalogClient.reduceReservationCount(itemId, order.fulfilmentWarehouseId, quantity)
-
 
2822
                    catalogClient.reserveItemInWarehouse(itemId, fulfilmentWarehouseId, quantity)
2821
                    accept_order(order.id)
2823
                    order.fulfilmentWarehouseId = fulfilmentWarehouseId
2822
                    quantity -= lineitem.quantity
2824
                    quantity -= lineitem.quantity
-
 
2825
                    session.commit()
2823
                    if not quantity:
2826
                    if not quantity:
2824
                        break
2827
                        break
2825
 
2828
 
2826
def close_session():
2829
def close_session():
2827
    if session.is_active:
2830
    if session.is_active: