Esempio n. 1
0
def release_inventory(orderitem):
    from sap.views import inward_event
    if orderitem.is_inventory_blocked:
        #Get inventory log entries for this order item
        physical_inventory_log = InventoryLog.objects.select_related(
            'rate_chart','dc').filter(
            orderitem=orderitem,
            inventory__type = 'physical')

        virtual_inventory_log = InventoryLog.objects.select_related(
            'rate_chart','dc').filter(
            orderitem=orderitem,
            inventory__type = 'virtual')

        if physical_inventory_log:
            inventory_log = physical_inventory_log[0]
            inward_event(request, inventory_log.rate_chart, 
                inventory_log.dc, 
                (inventory_log.new_bookings - inventory_log.was_bookings))

        if virtual_inventory_log:
            inventory_log = virtual_inventory_log[0]
            inventory_update_errors = inventory_log.inventory.increment_virtual_inventory(request, 
                (inventory_log.new_bookings - inventory_log.was_bookings), inventory_log)

        orderitem.is_inventory_blocked = False
        orderitem.save(force_update=True)
Esempio n. 2
0
def release_inventory(orderitem):
    from sap.views import inward_event
    if orderitem.is_inventory_blocked:
        #Get inventory log entries for this order item
        physical_inventory_log = InventoryLog.objects.select_related(
            'rate_chart', 'dc').filter(orderitem=orderitem,
                                       inventory__type='physical')

        virtual_inventory_log = InventoryLog.objects.select_related(
            'rate_chart', 'dc').filter(orderitem=orderitem,
                                       inventory__type='virtual')

        if physical_inventory_log:
            inventory_log = physical_inventory_log[0]
            inward_event(
                request, inventory_log.rate_chart, inventory_log.dc,
                (inventory_log.new_bookings - inventory_log.was_bookings))

        if virtual_inventory_log:
            inventory_log = virtual_inventory_log[0]
            inventory_update_errors = inventory_log.inventory.increment_virtual_inventory(
                request,
                (inventory_log.new_bookings - inventory_log.was_bookings),
                inventory_log)

        orderitem.is_inventory_blocked = False
        orderitem.save(force_update=True)
Esempio n. 3
0
def release_inventory(orderitem):
    from sap.views import inward_event
    log.info('orderitem.is_inventory_blocked = %s' %
             orderitem.is_inventory_blocked)
    if orderitem.is_inventory_blocked:
        vi_adjustment = Decimal('0')
        dc = None
        dclsp = InventoryDcLspResolution.objects.select_related(
            'orderitem__seller_rate_chart',
            'dc').filter(orderitem=orderitem,
                         is_valid=True).order_by('-created_on')

        if dclsp and \
            dclsp[0].stock_to_be_allocated > 0 and \
            dclsp[0].stock_allocated == False and \
            dclsp[0].is_valid == True:
            vi_adjustment = dclsp[0].stock_to_be_allocated

        #Invalidate DC-LSP enries.
        if dclsp:
            dc = dclsp[0].dc
            for item in dclsp:
                item.is_valid = False
                item.save()

        if dc:
            #Virtual stock adjustment
            virtual_inventory_log = InventoryLog.objects.select_related(
                'rate_chart', 'dc').filter(orderitem=orderitem,
                                           dc=dc,
                                           inventory__type__in=[
                                               'backorder', 'madetoorder',
                                               'preorder'
                                           ]).order_by('-created_on')

            if virtual_inventory_log:
                inventory_log = virtual_inventory_log[0]
                inventory_update_errors = inventory_log.inventory.increment_virtual_inventory(
                    request,
                    (inventory_log.new_bookings - inventory_log.was_bookings),
                    inventory_log)

            #Physical stock adjustment
            physical_adjustment = (orderitem.qty - vi_adjustment)
            if physical_adjustment:
                inward_event(request, orderitem.seller_rate_chart, dc,
                             physical_adjustment)

        orderitem.is_inventory_blocked = False
        orderitem.save(force_update=True)
        log.info('Successfully released inventory %s' % orderitem.id)
Esempio n. 4
0
def release_inventory(orderitem):
    from sap.views import inward_event
    log.info('orderitem.is_inventory_blocked = %s' % orderitem.is_inventory_blocked)
    if orderitem.is_inventory_blocked:
        vi_adjustment = Decimal('0')
        dc = None
        dclsp = InventoryDcLspResolution.objects.select_related(
            'orderitem__seller_rate_chart','dc').filter(
            orderitem = orderitem,
            is_valid = True).order_by('-created_on')

        if dclsp and \
            dclsp[0].stock_to_be_allocated > 0 and \
            dclsp[0].stock_allocated == False and \
            dclsp[0].is_valid == True:
            vi_adjustment = dclsp[0].stock_to_be_allocated
            
        #Invalidate DC-LSP enries.
        if dclsp:
            dc = dclsp[0].dc
            for item in dclsp:
                item.is_valid = False
                item.save()

        if dc:
            #Virtual stock adjustment
            virtual_inventory_log = InventoryLog.objects.select_related(
                'rate_chart','dc').filter(
                orderitem = orderitem,
                dc = dc,
                inventory__type__in=['backorder','madetoorder','preorder']).order_by('-created_on')

            if virtual_inventory_log:
                inventory_log = virtual_inventory_log[0]
                inventory_update_errors = inventory_log.inventory.increment_virtual_inventory(request, 
                    (inventory_log.new_bookings - inventory_log.was_bookings), inventory_log)

            #Physical stock adjustment
            physical_adjustment = (orderitem.qty - vi_adjustment)
            if physical_adjustment:
                inward_event(request, orderitem.seller_rate_chart,
                    dc, physical_adjustment)


        orderitem.is_inventory_blocked = False
        orderitem.save(force_update=True)
        log.info('Successfully released inventory %s' % orderitem.id)