2018-04-11

      _.map(selectedLisings, function (listing) {
        let deferred = $q.defer()
        if (listing.unit_group_id) {
          DashboardFactory.getUomById(listing.unit_group_id).success(function(data){
            deferred.resolve(data.unit_group.units)
          })
        } else {
          deferred.resolve([{name: "m"}])
        }
        deferred.promise.then(function(options){
          console.log(options)
          calculateCost(listing.id).then(function (data) {
            listing.cost = data.cost;
            const newPoItem = {
              name: listing.name,
              upc: listing.upc,
              product_id: listing.product_id,
              cost: Number(listing.cost),
              supplier_price: rate === null ? Number(listing.cost) : rate * Number(listing.cost),
              // Price is cost for some reason
              price: Number(listing.cost),
              retail_price: Number(listing.price),
              inventory_quantity: Number(listing.quantity),
              quantity: Number(listing.qtyRequested),
              qty_received: 0,
              qty_requested: Number(listing.qtyRequested),
              source_id: listing.id,
              source_type: 'Listing',
              suppliers: data.listing.suppliers,
              supplier_id: data.listing.supplier_id,
              units: options,
              display_unit_id: listing.base_unit.id,
              display_unit: listing.base_unit.name
            };
            const target = _.find($scope.order.purchase_items, item =>
                                                                item.source_type === newPoItem.source_type &&
                                                                item.source_id === newPoItem.source_id);
            if (target){
              target.quantity += newPoItem.quantity;
            } else {
              $scope.order.purchase_items.push(newPoItem);
            }
          });
        })
      });

你可能感兴趣的:(2018-04-11)