Search in sources :

Example 1 with IncomingDocAsOrderViewModel

use of org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel in project estatio by estatio.

the class IncomingDocAsOrderViewModel_Test method double_order_check_works.

@Test
public void double_order_check_works() throws Exception {
    // given
    IncomingDocAsOrderViewModel incomingDocAsOrderViewModel = new IncomingDocAsOrderViewModel();
    incomingDocAsOrderViewModel.orderRepository = mockOrderRepository;
    Order newOrder = new Order();
    incomingDocAsOrderViewModel.setDomainObject(newOrder);
    String sellerOrderReference = "123-456-7";
    Organisation seller = new Organisation();
    LocalDate orderDate = new LocalDate(2017, 01, 01);
    Order existingOrder = new Order();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderRepository).findBySellerOrderReferenceAndSellerAndOrderDate(sellerOrderReference, seller, orderDate);
            will(returnValue(newOrder));
            oneOf(mockOrderRepository).findBySellerOrderReferenceAndSeller(sellerOrderReference, seller);
            will(returnValue(Arrays.asList(newOrder, existingOrder)));
        }
    });
    // when
    incomingDocAsOrderViewModel.setSellerOrderReference(sellerOrderReference);
    incomingDocAsOrderViewModel.setSeller(seller);
    incomingDocAsOrderViewModel.setOrderDate(orderDate);
    String message = incomingDocAsOrderViewModel.doubleOrderCheck();
    // then
    Assertions.assertThat(message).contains("WARNING: Orders with the same seller order reference of this seller are found");
    // and expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderRepository).findBySellerOrderReferenceAndSellerAndOrderDate(sellerOrderReference, seller, orderDate);
            will(returnValue(existingOrder));
        }
    });
    // when
    message = incomingDocAsOrderViewModel.doubleOrderCheck();
    // then
    Assertions.assertThat(message).isEqualTo("WARNING: There is already an order with the same seller order reference and order date for this seller. Please check.");
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Expectations(org.jmock.Expectations) Organisation(org.estatio.module.party.dom.Organisation) LocalDate(org.joda.time.LocalDate) IncomingDocAsOrderViewModel(org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel) Test(org.junit.Test)

Example 2 with IncomingDocAsOrderViewModel

use of org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel in project estatio by estatio.

the class IncomingDocAsOrderViewModel_Test method mixin_save_works.

@Test
public void mixin_save_works() throws Exception {
    // given
    IncomingDocAsOrderViewModel incomingDocAsOrderViewModel = new IncomingDocAsOrderViewModel();
    Order order = new Order();
    incomingDocAsOrderViewModel.clockService = mockClockService;
    order.orderItemRepository = mockOrderItemRepository;
    incomingDocAsOrderViewModel.setDomainObject(order);
    BigDecimal netAmount = new BigDecimal("100.00");
    BigDecimal vatAmount = new BigDecimal("20.00");
    BigDecimal grossAmount = new BigDecimal("120.00");
    incomingDocAsOrderViewModel.setNetAmount(netAmount);
    incomingDocAsOrderViewModel.setVatAmount(vatAmount);
    incomingDocAsOrderViewModel.setGrossAmount(grossAmount);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockClockService).now();
            will(returnValue(new LocalDate(2017, 01, 01)));
            oneOf(mockOrderItemRepository).upsert(order, null, null, netAmount, vatAmount, grossAmount, null, null, null, null, null, null);
        }
    });
    // when
    incomingDocAsOrderViewModel.save();
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Expectations(org.jmock.Expectations) LocalDate(org.joda.time.LocalDate) IncomingDocAsOrderViewModel(org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with IncomingDocAsOrderViewModel

use of org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel in project estatio by estatio.

the class OrderBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    checkParam("officeAdministrator", ec, Person.class);
    checkParam("document", ec, Document.class);
    checkParam("buyer", ec, Organisation.class);
    checkParam("seller", ec, Organisation.class);
    checkParam("property", ec, Property.class);
    checkParam("project", ec, Project.class);
    checkParam("entryDate", ec, LocalDate.class);
    checkParam("itemTax", ec, Tax.class);
    checkParam("item1Description", ec, String.class);
    checkParam("item1NetAmount", ec, BigDecimal.class);
    checkParam("item1VatAmount", ec, BigDecimal.class);
    checkParam("item1GrossAmount", ec, BigDecimal.class);
    checkParam("item1Charge", ec, Charge.class);
    checkParam("item1Period", ec, String.class);
    checkParam("item2Description", ec, String.class);
    checkParam("item2NetAmount", ec, BigDecimal.class);
    checkParam("item2VatAmount", ec, BigDecimal.class);
    checkParam("item2GrossAmount", ec, BigDecimal.class);
    checkParam("item2Charge", ec, Charge.class);
    checkParam("item2Period", ec, String.class);
    // given we categorise for a property
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(officeAdministrator.getUsername(), () -> {
        final String comment = "";
        wrap(mixin(Document_categoriseAsOrder.class, document)).act(property, comment);
        // given most/all of the info has been completed  (not using our view model here).
        final String documentName = document.getName();
        Order order = orderRepository.findOrderByDocumentName(documentName).get(0);
        // only way to create a first order item "legally" is through the view model
        final IncomingDocAsOrderViewModel viewModel = mixin(Order_switchView.class, order).act();
        final IncomingDocAsOrderViewModel.changeOrderDetails changeOrderDetails = mixin(IncomingDocAsOrderViewModel.changeOrderDetails.class, viewModel);
        wrap(changeOrderDetails).act(changeOrderDetails.default0Act(), buyer, seller, changeOrderDetails.default3Act(), changeOrderDetails.default4Act());
        wrap(viewModel).setTax(itemTax);
        wrap(viewModel).setProperty(property);
        wrap(viewModel).setProject(project);
        wrap(viewModel).editCharge(item1Charge);
        wrap(viewModel).setDescription(item1Description);
        wrap(viewModel).setNetAmount(item1NetAmount);
        wrap(viewModel).setVatAmount(item1VatAmount);
        wrap(viewModel).setGrossAmount(item1GrossAmount);
        wrap(viewModel).setPeriod(item1Period);
        wrap(viewModel).setBudgetItem(null);
        wrap(viewModel).save();
        wrap(order).changeDates(order.default0ChangeDates(), entryDate);
        // this does an upsert base on the charge, so we still end up with only one item
        wrap(order).addItem(item1Charge, item1Description, item1NetAmount, item1VatAmount, item1GrossAmount, itemTax, // not a typo, but presumably the original fixture was wrong... guessing the upsert doesn't actually update this field
        item2Period, property, project, null);
        // add a different charge; this creates a second item
        wrap(order).addItem(item2Charge, item2Description, item2NetAmount, item2VatAmount, item2GrossAmount, itemTax, item2Period, property, project, null);
        this.object = order;
    });
    final List<OrderItem> items = Lists.newArrayList(this.object.getItems());
    firstItem = items.get(0);
    secondItem = items.get(1);
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Document_categoriseAsOrder(org.estatio.module.capex.dom.documents.categorisation.triggers.Document_categoriseAsOrder) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ToString(lombok.ToString) IncomingDocAsOrderViewModel(org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel) Order_switchView(org.estatio.module.capex.app.order.Order_switchView)

Example 4 with IncomingDocAsOrderViewModel

use of org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel in project estatio by estatio.

the class PdfAdvisorForEstatio method bookmarkFor.

private String bookmarkFor(final InstanceKey instanceKey) {
    Document document = determineDocument(instanceKey);
    InstanceKey.TypeKey typeKey = instanceKey.getTypeKey();
    String objectType = typeKey.getObjectType();
    if (Objects.equals(objectType, IncomingDocAsInvoiceViewModel.class.getName())) {
        String identifier = instanceKey.getIdentifier();
        final String xmlStr = urlEncodingService.decode(identifier);
        IncomingDocAsInvoiceViewModel viewModel = jaxbService.fromXml(IncomingDocAsInvoiceViewModel.class, xmlStr);
        final Bookmark bookmark = bookmarkService2.bookmarkFor(viewModel.getDocument());
        if (bookmark != null)
            return "incomingInvoiceViewModel:" + bookmark.getIdentifier();
        else {
            // object presumably deleted
            return null;
        }
    } else if (Objects.equals(objectType, IncomingDocAsOrderViewModel.class.getName())) {
        String identifier = instanceKey.getIdentifier();
        final String xmlStr = urlEncodingService.decode(identifier);
        IncomingDocAsOrderViewModel viewModel = jaxbService.fromXml(IncomingDocAsOrderViewModel.class, xmlStr);
        final Bookmark bookmark = bookmarkService2.bookmarkFor(viewModel.getDocument());
        if (bookmark != null)
            return "incomingOrderViewModel:" + bookmark.getIdentifier();
        else {
            // object presumably deleted
            return null;
        }
    } else {
        return instanceKey.asBookmark().toString();
    }
}
Also used : Bookmark(org.apache.isis.applib.services.bookmark.Bookmark) IncomingDocAsInvoiceViewModel(org.estatio.module.capex.app.invoice.IncomingDocAsInvoiceViewModel) Document(org.incode.module.document.dom.impl.docs.Document) IncomingDocAsOrderViewModel(org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel)

Aggregations

IncomingDocAsOrderViewModel (org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel)4 Order (org.estatio.module.capex.dom.order.Order)3 Expectations (org.jmock.Expectations)2 LocalDate (org.joda.time.LocalDate)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 ToString (lombok.ToString)1 Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)1 IncomingDocAsInvoiceViewModel (org.estatio.module.capex.app.invoice.IncomingDocAsInvoiceViewModel)1 Order_switchView (org.estatio.module.capex.app.order.Order_switchView)1 Document_categoriseAsOrder (org.estatio.module.capex.dom.documents.categorisation.triggers.Document_categoriseAsOrder)1 OrderItem (org.estatio.module.capex.dom.order.OrderItem)1 Organisation (org.estatio.module.party.dom.Organisation)1 Document (org.incode.module.document.dom.impl.docs.Document)1