Search in sources :

Example 11 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel_Test method notification_BuyerBarcodeMatchValidation_works.

@Test
public void notification_BuyerBarcodeMatchValidation_works() {
    String notification;
    // given
    IncomingDocAsInvoiceViewModel viewModel = new IncomingDocAsInvoiceViewModel();
    Party buyerDerived = new Organisation();
    BuyerFinder buyerFinder = new BuyerFinder() {

        @Override
        public Party buyerDerivedFromDocumentName(final IncomingInvoice incomingInvoice) {
            return buyerDerived;
        }
    };
    IncomingInvoice invoice = new IncomingInvoice();
    Party buyerOnViewmodel = new Organisation();
    viewModel.setDomainObject(invoice);
    viewModel.buyerFinder = buyerFinder;
    viewModel.setBuyer(buyerOnViewmodel);
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isEqualTo("Buyer does not match barcode (document name); ");
    // and given (buyers matching)
    viewModel.setBuyer(buyerDerived);
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isNull();
    // and given (no buyer derived)
    BuyerFinder buyerFinderReturningNull = new BuyerFinder() {

        @Override
        public Party buyerDerivedFromDocumentName(final IncomingInvoice incomingInvoice) {
            return null;
        }
    };
    viewModel.buyerFinder = buyerFinderReturningNull;
    // when
    notification = viewModel.getNotification();
    // then
    Assertions.assertThat(notification).isNull();
}
Also used : Party(org.estatio.module.party.dom.Party) BuyerFinder(org.estatio.module.capex.dom.documents.BuyerFinder) Organisation(org.estatio.module.party.dom.Organisation) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Test(org.junit.Test)

Example 12 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class DebtorBankAccountService_Test method unique_Debtor_Account_To_Pay_works_when_bankaccounts_and_one_for_property.

@Test
public void unique_Debtor_Account_To_Pay_works_when_bankaccounts_and_one_for_property() throws Exception {
    // given
    DebtorBankAccountService service = new DebtorBankAccountService();
    service.bankAccountRepository = mockBankAccountRepository;
    service.fixedAssetFinancialAccountRepository = mockFixedAssetFinancialAccountRepository;
    BankAccount bankAccount = new BankAccount();
    BankAccount bankAccountForProperty = new BankAccount();
    FixedAssetFinancialAccount fixedAssetFinancialAccount = new FixedAssetFinancialAccount();
    fixedAssetFinancialAccount.setFinancialAccount(bankAccountForProperty);
    List<BankAccount> bankAccounts = new ArrayList<>();
    bankAccounts.add(bankAccount);
    bankAccounts.add(bankAccountForProperty);
    IncomingInvoice invoice = new IncomingInvoice();
    Party debtor = new Organisation();
    invoice.setBuyer(debtor);
    Property property = new Property();
    invoice.setProperty(property);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockBankAccountRepository).findBankAccountsByOwner(debtor);
            will(returnValue(bankAccounts));
            oneOf(mockFixedAssetFinancialAccountRepository).findByFixedAsset(property);
            will(returnValue(Arrays.asList(fixedAssetFinancialAccount)));
        }
    });
    // when, then
    assertThat(service.uniqueDebtorAccountToPay(invoice)).isEqualTo(bankAccountForProperty);
}
Also used : Expectations(org.jmock.Expectations) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) ArrayList(java.util.ArrayList) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Example 13 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class DebtorBankAccountService_Test method unique_Debtor_Account_To_Pay_works_when_one_bankaccount_and_no_property.

@Test
public void unique_Debtor_Account_To_Pay_works_when_one_bankaccount_and_no_property() throws Exception {
    // given
    DebtorBankAccountService service = new DebtorBankAccountService();
    service.bankAccountRepository = mockBankAccountRepository;
    BankAccount bankAccount = new BankAccount();
    IncomingInvoice invoice = new IncomingInvoice();
    Party debtor = new Organisation();
    invoice.setBuyer(debtor);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockBankAccountRepository).findBankAccountsByOwner(debtor);
            will(returnValue(Arrays.asList(bankAccount)));
        }
    });
    // when, then
    assertThat(service.uniqueDebtorAccountToPay(invoice)).isEqualTo(bankAccount);
}
Also used : Expectations(org.jmock.Expectations) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Test(org.junit.Test)

Example 14 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class IncomingInvoiceMenu_Test method filterOrFindByGrossAmount_negative_amounts_find_works.

@Test
public void filterOrFindByGrossAmount_negative_amounts_find_works() {
    IncomingInvoiceMenu.IncomingInvoiceFinder builder;
    // given
    builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
    IncomingInvoice invoice1 = new IncomingInvoice();
    IncomingInvoice invoice2 = new IncomingInvoice();
    IncomingInvoice invoice3 = new IncomingInvoice();
    invoice1.setGrossAmount(new BigDecimal("-9.50"));
    invoice2.setGrossAmount(new BigDecimal("-10.50"));
    invoice3.setGrossAmount(new BigDecimal("-10.51"));
    final BigDecimal amountSearchedFor = new BigDecimal("-10.00");
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).listAll();
            will(returnValue(Arrays.asList(invoice1, invoice2, invoice3)));
        }
    });
    // when
    builder.filterOrFindByGrossAmount(amountSearchedFor);
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    Assertions.assertThat(builder.getResult()).contains(invoice1);
    Assertions.assertThat(builder.getResult()).contains(invoice2);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class IncomingInvoiceMenu_Test method filterOrFindInvoiceDate_filter_works.

@Test
public void filterOrFindInvoiceDate_filter_works() {
    IncomingInvoiceMenu.IncomingInvoiceFinder builder;
    // given
    builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
    IncomingInvoice invoice1 = new IncomingInvoice();
    IncomingInvoice invoice2 = new IncomingInvoice();
    IncomingInvoice invoice3 = new IncomingInvoice();
    invoice1.setInvoiceDate(new LocalDate(2017, 7, 15));
    invoice2.setInvoiceDate(new LocalDate(2017, 7, 5));
    invoice3.setInvoiceDate(new LocalDate(2017, 7, 16));
    builder.setResult(Arrays.asList(invoice1, invoice2, invoice3));
    final LocalDate dateSearchedFor = new LocalDate(2017, 7, 10);
    Assertions.assertThat(builder.getResult().size()).isEqualTo(3);
    // when
    builder.filterOrFindByInvoiceDate(dateSearchedFor);
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    Assertions.assertThat(builder.getResult()).contains(invoice1);
    Assertions.assertThat(builder.getResult()).contains(invoice2);
}
Also used : IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)57 Test (org.junit.Test)27 Expectations (org.jmock.Expectations)20 BankAccount (org.estatio.module.financial.dom.BankAccount)14 Action (org.apache.isis.applib.annotation.Action)11 BigDecimal (java.math.BigDecimal)9 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)9 Organisation (org.estatio.module.party.dom.Organisation)9 Party (org.estatio.module.party.dom.Party)9 IncomingInvoiceMenu (org.estatio.module.capex.app.IncomingInvoiceMenu)8 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)7 Document (org.incode.module.document.dom.impl.docs.Document)7 LocalDate (org.joda.time.LocalDate)7 ArrayList (java.util.ArrayList)5 Programmatic (org.apache.isis.applib.annotation.Programmatic)5 Property (org.estatio.module.asset.dom.Property)3 UpcomingPaymentTotal (org.estatio.module.capex.app.invoice.UpcomingPaymentTotal)3 BuyerFinder (org.estatio.module.capex.dom.documents.BuyerFinder)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 OrderItem (org.estatio.module.capex.dom.order.OrderItem)3