               deferred.reject msg
           .fail (msg) ->
             deferred.reject msg
-      .fail (msg) ->
-        deferred.reject msg
+        .fail (msg) ->
+          deferred.reject msg
     .fail (msg) ->
       deferred.reject msg
     deferred.promise

    if _.size(orders) is 0
      @returnResult true, 'Nothing to do.', callback
      return
    promises = []
    for order in orders
      promises.push @modifyOrder(order)
#    @initProgressBar 'Updating Inventory', _.size(promises)
    Q.all(promises).then (msg) =>
      @returnResult true, msg, callback
    .fail (msg) =>

  modifyOrder: (order) ->
    deferred = Q.defer()
    @getState(order).then (state) =>
      result = @modifyState order, state
      posts = []
      for action in result.actions
        posts.push @updateInventoryEntry(action)
      @tickProgress()
      if _.size(posts) is 0
        deferred.resolve "Nothing to update."
      else
        mod = _.clone(state)
        mod.status = @STATE_MODIFING
        @saveState(order, mod).then (msg) =>
          Q.all(posts).then (msg) =>
            @saveState(order, result.state).then (msg) ->
              deferred.resolve "Inventory updated."
