use of org.estatio.module.party.dom.Party in project estatio by estatio.
the class OrderRepository_Test method upsert_when_already_exists.
@Test
public void upsert_when_already_exists() throws Exception {
// given
OrderRepository orderRepository = new OrderRepository() {
@Override
public Order findByOrderNumber(final String orderNumber) {
return order;
}
};
String number = "some number";
String sellerOrderReference = "ref";
LocalDate entryDate = new LocalDate(2017, 1, 1);
LocalDate orderDate = new LocalDate(2017, 1, 2);
Party seller = new Organisation();
Party buyer = new Organisation();
Property property = new Property();
String atPath = "atPath";
OrderApprovalState approvalState = OrderApprovalState.APPROVED;
assertThat(order.getOrderNumber()).isNull();
// when
orderRepository.upsert(property, number, sellerOrderReference, entryDate, orderDate, seller, buyer, atPath, approvalState);
// then
assertThat(order.getOrderNumber()).isNull();
assertThat(order.getSellerOrderReference()).isEqualTo(sellerOrderReference);
assertThat(order.getEntryDate()).isEqualTo(entryDate);
assertThat(order.getOrderDate()).isEqualTo(orderDate);
assertThat(order.getSeller()).isEqualTo(seller);
assertThat(order.getBuyer()).isEqualTo(buyer);
assertThat(order.getProperty()).isEqualTo(property);
assertThat(order.getAtPath()).isEqualTo(atPath);
// is ignored.
assertThat(order.getApprovalState()).isNull();
}
use of org.estatio.module.party.dom.Party in project estatio by estatio.
the class IncomingInvoiceRepository_IntegTest method upsert_works.
@Test
public void upsert_works() throws Exception {
// given
IncomingInvoice existingInvoice = createIncomingInvoice();
IncomingInvoice invoice = incomingInvoiceRepository.findByInvoiceNumberAndSellerAndInvoiceDate(invoiceNumber, seller, invoiceDate);
assertThat(invoice.getInvoiceNumber()).isEqualTo(invoiceNumber);
assertThat(invoice.getAtPath()).isEqualTo(atPath);
assertThat(invoice.getBuyer()).isEqualTo(buyer);
assertThat(invoice.getDueDate()).isEqualTo(dueDate);
assertThat(invoice.getPaymentMethod()).isEqualTo(paymentMethod);
assertThat(invoice.getStatus()).isEqualTo(invoiceStatus);
assertThat(invoice.getDateReceived()).isNull();
assertThat(invoice.getBankAccount()).isNull();
// when
String updatedAtPath = "/NLD";
Party updatedBuyer = Organisation_enum.HelloWorldNl.findUsing(serviceRegistry);
LocalDate updatedDueDate = dueDate.minusWeeks(1);
PaymentMethod updatedPaymentMethod = PaymentMethod.DIRECT_DEBIT;
InvoiceStatus updatedStatus = InvoiceStatus.INVOICED;
LocalDate updatedDateReceived = new LocalDate(2017, 1, 2);
BankAccount updatedBankAccount = bankAccountRepository.allBankAccounts().get(0);
Property property = existingInvoice.getProperty();
IncomingInvoice updatedInvoice = incomingInvoiceRepository.upsert(IncomingInvoiceType.CAPEX, invoiceNumber, property, updatedAtPath, updatedBuyer, seller, invoiceDate, updatedDueDate, updatedPaymentMethod, updatedStatus, updatedDateReceived, updatedBankAccount, null);
// then
assertThat(updatedInvoice.getInvoiceNumber()).isEqualTo(invoiceNumber);
assertThat(updatedInvoice.getSeller()).isEqualTo(seller);
assertThat(updatedInvoice.getInvoiceDate()).isEqualTo(invoiceDate);
assertThat(updatedInvoice.getAtPath()).isEqualTo(updatedAtPath);
assertThat(updatedInvoice.getBuyer()).isEqualTo(updatedBuyer);
assertThat(updatedInvoice.getDueDate()).isEqualTo(updatedDueDate);
assertThat(updatedInvoice.getPaymentMethod()).isEqualTo(updatedPaymentMethod);
assertThat(updatedInvoice.getStatus()).isEqualTo(updatedStatus);
assertThat(updatedInvoice.getDateReceived()).isEqualTo(updatedDateReceived);
assertThat(updatedInvoice.getBankAccount()).isEqualTo(updatedBankAccount);
}
use of org.estatio.module.party.dom.Party in project estatio by estatio.
the class BankAccountRepository_Test method findBankAccountsByOwner_filters_deprecated.
@Test
public void findBankAccountsByOwner_filters_deprecated() throws Exception {
// given
BankAccountRepository repo = new BankAccountRepository();
repo.financialAccountRepository = mockFARepo;
Party party = new Organisation();
BankAccount account1 = new BankAccount();
BankAccount account2 = new BankAccount();
// expect
context.checking(new Expectations() {
{
oneOf(mockFARepo).findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
will(returnValue(Arrays.asList(account1, account2)));
}
});
// when
List<BankAccount> result = repo.findBankAccountsByOwner(party);
Assertions.assertThat(result.size()).isEqualTo(2);
Assertions.assertThat(result).contains(account1);
Assertions.assertThat(result).contains(account2);
// and given
account2.setDeprecated(true);
// expect
context.checking(new Expectations() {
{
oneOf(mockFARepo).findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
will(returnValue(Arrays.asList(account1, account2)));
}
});
// when
result = repo.findBankAccountsByOwner(party);
Assertions.assertThat(result.size()).isEqualTo(1);
Assertions.assertThat(result).contains(account1);
Assertions.assertThat(result).doesNotContain(account2);
}
use of org.estatio.module.party.dom.Party in project estatio by estatio.
the class PartyBankAccountsAndMandatesDtoFactory method newDto.
@Programmatic
public BankAccountsAndMandatesDto newDto(final Party party) {
final BankAccountsAndMandatesDto dto = new BankAccountsAndMandatesDto();
final List<FinancialAccount> financialAccountList = financialAccountRepository.findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
final List<BankAccountDto> bankAccountDtos = financialAccountList.stream().map(x -> bankAccountDtoFactory.newDto((BankAccount) x)).collect(Collectors.toList());
dto.setBankAccounts(bankAccountDtos);
final AgreementType bankMandateAt = agreementTypeRepository.find(BankMandateAgreementTypeEnum.MANDATE);
final AgreementRoleType debtorOfMandate = agreementRoleTypeRepository.findByAgreementTypeAndTitle(bankMandateAt, BankMandateAgreementRoleTypeEnum.DEBTOR.getTitle());
final List<AgreementRole> agreementRoles = agreementRoleRepository.findByPartyAndType(party, debtorOfMandate);
final List<BankMandateDto> mandateDtos = agreementRoles.stream().map(x -> x.getAgreement()).map(x -> bankMandateDtoFactory.newDto((BankMandate) x)).collect(Collectors.toList());
dto.setBankMandates(mandateDtos);
return dto;
}
use of org.estatio.module.party.dom.Party in project estatio by estatio.
the class BankAccountImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
if (IBANValidator.valid(iban)) {
final Party owner = partyRepository.findPartyByReference(ownerReference);
BankAccount bankAccount = (BankAccount) financialAccountRepository.findByOwnerAndReference(owner, iban);
if (owner == null)
return Lists.newArrayList();
if (bankAccount == null) {
bankAccount = bankAccountRepository.newBankAccount(owner, iban, bic);
} else {
bankAccount.setIban(iban);
bankAccount.verifyIban();
bankAccount.setBic(BankAccount.trimBic(bic));
}
if (propertyReference != null) {
final Property property = propertyRepository.findPropertyByReference(propertyReference);
if (property == null) {
throw new IllegalArgumentException(String.format("Property with reference [%s] not found", propertyReference));
}
fixedAssetFinancialAccountRepository.findOrCreate(property, bankAccount);
}
}
return Lists.newArrayList();
}
Aggregations