protected Integer calcTotalUnitCount(final AbstractOrderModel source) {
   int totalUnitCount = 0;
   for (final AbstractOrderEntryModel orderEntryModel : source.getEntries()) {
     totalUnitCount += orderEntryModel.getQuantity().intValue();
   }
   return Integer.valueOf(totalUnitCount);
 }
 @Override
 public Object getGroupingObject(final AbstractOrderEntryModel orderEntry) {
   return orderEntry.getDeliveryMode() != null
       ? orderEntry.getDeliveryMode()
       : orderEntry.getDeliveryPointOfService() == null
           ? orderEntry.getOrder().getDeliveryMode()
           : getPickupDeliveryModeDao()
               .findPickupDeliveryModesForAbstractOrder(orderEntry.getOrder())
               .get(0);
 }
  protected double getProductsDiscountsAmount(final AbstractOrderModel source) {
    double discounts = 0.0d;

    final List<AbstractOrderEntryModel> entries = source.getEntries();
    if (entries != null) {
      for (final AbstractOrderEntryModel entry : entries) {
        final List<DiscountValue> discountValues = entry.getDiscountValues();
        if (discountValues != null) {
          for (final DiscountValue dValue : discountValues) {
            discounts += dValue.getAppliedValue();
          }
        }
      }
    }
    return discounts;
  }
  protected boolean checkDeliveryOptions(final OrderModel order) {
    if (order.getDeliveryMode() == null) {
      // Order must have an overall delivery mode
      return false;
    }

    if (order.getDeliveryAddress() == null) {
      for (final AbstractOrderEntryModel entry : order.getEntries()) {
        if (entry.getDeliveryPointOfService() == null && entry.getDeliveryAddress() == null) {
          // Order and Entry have no delivery address and some entries are not for pickup
          return false;
        }
      }
    }

    return true;
  }
  @Test
  public void testManualOrderEntryPositions() {
    final OrderModel newOne = createNewOrder();

    // take out entries
    final List<AbstractOrderEntryModel> entries = newOne.getEntries();
    newOne.setEntries(null);

    modelService.save(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertEquals(Collections.EMPTY_LIST, newOne.getEntries());

    Assert.assertTrue(modelService.isNew(entries.get(0)));
    Assert.assertTrue(modelService.isNew(entries.get(1)));
    Assert.assertTrue(modelService.isNew(entries.get(2)));
    Assert.assertTrue(modelService.isNew(entries.get(3)));

    // now save in reverse order
    AbstractOrderEntryModel entry = entries.get(3);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(3), entry.getEntryNumber());

    entry = entries.get(2);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(2), entry.getEntryNumber());

    entry = entries.get(1);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(1), entry.getEntryNumber());

    entry = entries.get(0);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(0), entry.getEntryNumber());

    modelService.refresh(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertFalse(modelService.isNew(entries.get(0)));
    Assert.assertFalse(modelService.isNew(entries.get(1)));
    Assert.assertFalse(modelService.isNew(entries.get(2)));
    Assert.assertFalse(modelService.isNew(entries.get(3)));

    assertEntriesOrder(newOne);
  }
 private void displayEntries(final OrderModel order, final String prefix) {
   System.out.println(prefix + "Order@" + System.identityHashCode(order));
   final List<AbstractOrderEntryModel> entries = order.getEntries();
   if (entries != null && !entries.isEmpty()) {
     for (final AbstractOrderEntryModel entry : entries) {
       System.out.println(
           prefix
               + "Entry@"
               + System.identityHashCode(entry)
               + ", Entry.PK="
               + entry.getPk()
               + ", Entry.EntryNumber="
               + entry.getEntryNumber()
               + ", Entry.Product.PK="
               + entry.getProduct().getPk()
               + ", Entry.Product.Code="
               + entry.getProduct().getCode());
     }
   }
 }
  @Override
  public void executeAction(final OrderProcessModel process) throws Exception {
    if (LOG.isInfoEnabled()) {
      LOG.info("Process: " + process.getCode() + " in step " + getClass());
    }

    // find the order's entries that are not already allocated to consignments
    final List<AbstractOrderEntryModel> entriesToSplit = new ArrayList<AbstractOrderEntryModel>();
    for (final AbstractOrderEntryModel entry : process.getOrder().getEntries()) {
      if (entry.getConsignmentEntries() == null || entry.getConsignmentEntries().isEmpty()) {
        entriesToSplit.add(entry);
      }
    }

    final List<ConsignmentModel> consignments =
        getOrderSplittingService().splitOrderForConsignment(process.getOrder(), entriesToSplit);

    if (LOG.isDebugEnabled()) {
      LOG.debug("Splitting order into " + consignments.size() + " consignments.");
    }

    final BusinessProcessService businessProcessService = getBusinessProcessService();

    int index = 0;
    for (final ConsignmentModel consignment : consignments) {
      final ConsignmentProcessModel subProcess =
          businessProcessService.<ConsignmentProcessModel>createProcess(
              process.getCode() + "_" + (++index),
              MitreFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_NAME);

      subProcess.setParentProcess(process);
      subProcess.setConsignment(consignment);
      save(subProcess);

      businessProcessService.startProcess(subProcess);
    }
    setOrderStatus(process.getOrder(), OrderStatus.ORDER_SPLIT);
  }
Example #8
0
 @Override
 public Object getGroupingObject(final AbstractOrderEntryModel orderEntry) {
   return orderEntry.getDeliveryPointOfService();
 }
Example #9
0
  public ru.technonikol.ws.orders.Order convert(final OrderModel source)
      throws ConversionException {
    final ru.technonikol.ws.orders.Order target = new ru.technonikol.ws.orders.Order();
    final SimpleDateFormat serviceDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");

    try {
      if (source.getDeliveryAddress() != null) {
        final String fullAddress =
            source.getDeliveryAddress().getPostalcode()
                + ","
                + source.getDeliveryAddress().getTown()
                + ","
                + source.getDeliveryAddress().getLine2()
                + ","
                + source.getDeliveryAddress().getLine2();
        target.setAddress(fullAddress);
        target.setHouse(source.getDeliveryAddress().getLine2());
        target.setCountry(source.getDeliveryAddress().getCountry().getIsocode());
        target.setStreet(source.getDeliveryAddress().getStreetname());
        target.setTown(source.getDeliveryAddress().getTown());
        target.setAddressCode(source.getDeliveryAddress().getPostalcode());
        target.setRegion(source.getDeliveryAddress().getTown());
      } else {
        target.setAddress("");
        target.setHouse("");
        target.setCountry("");
        target.setStreet("");
        target.setTown("");
        target.setAddressCode("");
        target.setRegion("");
      }
      target.setCountryCode("695");
      target.setApartment("");
      target.setBuilding("");
      target.setCity("");
      target.setCityCode("");
      target.setRegionCode("77");

      target.setObjectType("664b64d0-403f-11e2-8e4e-005056010274"); // TODO no data now
      target.setConstructionType("1"); // TODO no data now

      target.setDate(serviceDateFormat.format(source.getCreationtime()));

      target.setPaymentType(source.getPaymentMethod().getCode());

      LOG.debug("User uid: " + source.getUser().getUid());
      target.setIDPartner(getPartnerID(source.getUser()));
      target.setNumber(source.getCode());
      target.setWarehouseGUID("");

      if (!CollectionUtils.isEmpty(source.getEntries())) {
        if (source.getEntries().get(0).getDeliveryPointOfService() != null) {
          final List<WarehouseModel> wrhs =
              source.getEntries().get(0).getDeliveryPointOfService().getWarehouses();
          if (!CollectionUtils.isEmpty(wrhs)) {
            target.setWarehouseGUID(wrhs.get(0).getCode());
          }
        }
      }

      final Materials materials = new Materials();

      for (final AbstractOrderEntryModel entry : source.getEntries()) {
        final MaterialsRow row = new MaterialsRow();

        row.setDeliveryDate("");
        if (source.getProvidedDeliveryDate() != null) {
          final Date entryDate = serviceDateFormat.parse(source.getProvidedDeliveryDate());
          row.setDeliveryDate(serviceDateFormat.format(entryDate));
        }
        double discountValue = 0;
        for (final DiscountValue discount : entry.getDiscountValues()) {
          discountValue += discount.getAppliedValue();
        }
        row.setDiscount(String.valueOf(discountValue));
        row.setEKN(entry.getProduct().getCode());
        row.setLineTotal(entry.getTotalPrice().toString());
        row.setPackage("");
        row.setPrice(entry.getBasePrice().toString());
        row.setQnty(entry.getQuantity().toString());
        row.setUserGroup("");
        materials.getRow().add(row);
      }
      target.setMaterials(materials);
    } catch (final Exception ex) {
      throw new ConversionException(
          "Error when trying to convert de.hybris.platform.core.model.order.OrderModel to ru.technonikol.ws.orders.Order",
          ex);
    }

    return target;
  }