private void assertEntriesOrder(final OrderModel order) { if (!modelService.isNew(order)) { Assert.assertEquals( "Unexpected product in order entry 1: ", product1, orderService.getEntryForNumber(order, 0).getProduct()); Assert.assertEquals( "Unexpected product in order entry 2: ", product2, orderService.getEntryForNumber(order, 1).getProduct()); Assert.assertEquals( "Unexpected product in order entry 3: ", product3, orderService.getEntryForNumber(order, 2).getProduct()); Assert.assertEquals( "Unexpected product in order entry 4: ", product4, orderService.getEntryForNumber(order, 3).getProduct()); } Assert.assertEquals( "Unexpected product in order entry 1: ", product1, order.getEntries().get(0).getProduct()); Assert.assertEquals( "Unexpected product in order entry 2: ", product2, order.getEntries().get(1).getProduct()); Assert.assertEquals( "Unexpected product in order entry 3: ", product3, order.getEntries().get(2).getProduct()); Assert.assertEquals( "Unexpected product in order entry 4: ", product4, order.getEntries().get(3).getProduct()); }
private void assertNew(final OrderModel order) { Assert.assertTrue(modelService.isNew(order)); Assert.assertTrue(modelService.isNew(order.getEntries().get(0))); Assert.assertTrue(modelService.isNew(order.getEntries().get(1))); Assert.assertTrue(modelService.isNew(order.getEntries().get(2))); Assert.assertTrue(modelService.isNew(order.getEntries().get(3))); }
private void assertSaved(final OrderModel order) { Assert.assertFalse(modelService.isNew(order)); Assert.assertFalse(modelService.isNew(order.getEntries().get(0))); Assert.assertFalse(modelService.isNew(order.getEntries().get(1))); Assert.assertFalse(modelService.isNew(order.getEntries().get(2))); Assert.assertFalse(modelService.isNew(order.getEntries().get(3))); Assert.assertTrue(modelService.isUpToDate(order)); Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(0))); Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(1))); Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(2))); Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(3))); }
@Test public void testSetEntryNumbersForNewEntriesHalfAutomatically() { final OrderModel order = createNewOrder(); modelService.save(order); final List<AbstractOrderEntryModel> oldEntries = order.getEntries(); Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber()); Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber()); Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber()); Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber()); final OrderEntryModel entry1 = createTestOrderEntry(order); entry1.setEntryNumber(5); final OrderEntryModel entry2 = createTestOrderEntry(order); entry2.setEntryNumber(4); final OrderEntryModel entry3 = createTestOrderEntry(order); final OrderEntryModel entry4 = createTestOrderEntry(order); modelService.saveAll(entry1, entry2, entry3, entry4); Assert.assertEquals(Integer.valueOf(5), entry1.getEntryNumber()); Assert.assertEquals(Integer.valueOf(4), entry2.getEntryNumber()); Assert.assertEquals(Integer.valueOf(6), entry3.getEntryNumber()); Assert.assertEquals(Integer.valueOf(7), entry4.getEntryNumber()); }
@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); }
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; }
@Override public boolean check(final OrderModel order) { if (!order.getCalculated().booleanValue()) { // Order must be calculated return false; } if (order.getEntries().isEmpty()) { // Order must have some lines return false; } else if (order.getPaymentInfo() == null) { // Order must have some payment info to use in the process return false; } else { // Order delivery options must be valid return checkDeliveryOptions(order); } }
@Test public void testSetEntryNumbersForAdditionalEntries() { final OrderModel order = createNewOrder(); modelService.save(order); final List<AbstractOrderEntryModel> oldEntries = order.getEntries(); Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber()); Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber()); Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber()); Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber()); final OrderEntryModel entry1 = createTestOrderEntry(order); final OrderEntryModel entry2 = createTestOrderEntry(order); modelService.saveAll(entry1, entry2); Assert.assertEquals(Integer.valueOf(4), entry1.getEntryNumber()); Assert.assertEquals(Integer.valueOf(5), entry2.getEntryNumber()); }
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()); } } }
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; }