Skip to content

Commit

Permalink
Bank statement line reference not marked as processed (#6513)
Browse files Browse the repository at this point in the history
#6511
(cherry picked from commit c39df8a)
  • Loading branch information
teosarca authored and metas-ts committed May 15, 2020
1 parent cb27e89 commit 77f1bb9
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private void createBankStatementLineRef(
final BankStatementLineReference lineRef = bankStatementDAO.createBankStatementLineRef(BankStatementLineRefCreateRequest.builder()
.bankStatementId(BankStatementId.ofRepoId(bankStatementLine.getC_BankStatement_ID()))
.bankStatementLineId(BankStatementLineId.ofRepoId(bankStatementLine.getC_BankStatementLine_ID()))
.processed(bankStatementLine.isProcessed())
//
.orgId(OrgId.ofRepoId(bankStatementLine.getAD_Org_ID()))
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BankStatementLineRefCreateRequest
BankStatementId bankStatementId;
@NonNull
BankStatementLineId bankStatementLineId;
boolean processed;

@NonNull
OrgId orgId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public BankStatementId createBankStatement(@NonNull final BankStatementCreateReq
record.setName(request.getName());
record.setDescription(request.getDescription());
record.setStatementDate(TimeUtil.asTimestamp(request.getStatementDate()));
record.setDocStatus(DocStatus.Drafted.getCode());
record.setDocAction(IDocument.ACTION_Complete);

final BankStatementCreateRequest.ElectronicFundsTransfer eft = request.getEft();
if (eft != null)
Expand Down Expand Up @@ -364,6 +366,7 @@ public BankStatementLineReference createBankStatementLineRef(@NonNull final Bank
record.setAD_Org_ID(request.getOrgId().getRepoId());
record.setC_BankStatement_ID(request.getBankStatementId().getRepoId());
record.setC_BankStatementLine_ID(request.getBankStatementLineId().getRepoId());
record.setProcessed(request.isProcessed());
record.setLine(request.getLineNo());

record.setC_BPartner_ID(request.getBpartnerId().getRepoId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_BankStatementLine;
import org.compiere.model.I_C_Payment;
import org.compiere.util.Trace;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
Expand All @@ -50,6 +51,10 @@
import de.metas.banking.BankStatementLineId;
import de.metas.banking.BankStatementLineReferenceList;
import de.metas.banking.api.BankAccountId;
import de.metas.banking.model.I_C_BankStatementLine_Ref;
import de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest;
import de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest.PaymentToLink;
import de.metas.banking.payment.BankStatementLineMultiPaymentLinkResult;
import de.metas.banking.payment.PaymentLinkResult;
import de.metas.banking.payment.impl.BankStatementPaymentBL;
import de.metas.banking.service.BankStatementCreateRequest;
Expand All @@ -60,6 +65,7 @@
import de.metas.banking.service.IBankStatementListenerService;
import de.metas.bpartner.BPartnerId;
import de.metas.business.BusinessTestHelper;
import de.metas.currency.Amount;
import de.metas.currency.CurrencyCode;
import de.metas.currency.CurrencyRepository;
import de.metas.currency.impl.PlainCurrencyDAO;
Expand All @@ -73,6 +79,7 @@
import de.metas.payment.api.IPaymentBL;
import de.metas.util.Services;
import de.metas.util.time.SystemTime;
import lombok.Builder;
import lombok.NonNull;

class BankStatementPaymentBLTest
Expand All @@ -93,6 +100,17 @@ class BankStatementPaymentBLTest
void beforeEach()
{
AdempiereTestHelper.get().init();

Services.registerService(IBankStatementBL.class, new BankStatementBL()
{
public void unpost(I_C_BankStatement bankStatement)
{
System.out.println("In JUnit test BankStatementBL.unpost() does nothing"
+ "\n\t bank statement: " + bankStatement
+ "\n\t called via " + Trace.toOneLineStackTraceString());
}
});

bankStatementListenerService = Services.get(IBankStatementListenerService.class);
bankStatementPaymentBL = new BankStatementPaymentBL(new MoneyService(new CurrencyRepository()));

Expand Down Expand Up @@ -137,10 +155,12 @@ private I_C_BankStatement createBankStatement(final BankAccountId orgBankAccount
return bankStatementDAO.getById(bankStatementId);
}

@Builder(builderMethodName = "bankStatementLine", builderClassName = "BankStatementLineBuilder")
private I_C_BankStatementLine createBankStatementLine(
final BankStatementId bankStatementId,
final BPartnerId bpartnerId,
final Money stmtAmt)
final Money stmtAmt,
final boolean processed)
{
final BankStatementLineId bankStatementLineId = bankStatementDAO.createBankStatementLine(BankStatementLineCreateRequest.builder()
.bankStatementId(bankStatementId)
Expand All @@ -153,7 +173,15 @@ private I_C_BankStatementLine createBankStatementLine(
.trxAmt(stmtAmt)
.build());

return bankStatementDAO.getLineById(bankStatementLineId);
final I_C_BankStatementLine bankStatementLine = bankStatementDAO.getLineById(bankStatementLineId);

if (processed)
{
bankStatementLine.setProcessed(true);
bankStatementDAO.save(bankStatementLine);
}

return bankStatementLine;
}

@Nested
Expand All @@ -165,10 +193,11 @@ public void checkListenerFired()
final BPartnerId customerId = createCustomer();

final I_C_BankStatement bankStatement = createBankStatement(euroOrgBankAccountId);
final I_C_BankStatementLine bankStatementLine = createBankStatementLine(
BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()),
customerId,
Money.of(-123, euroCurrencyId));
final I_C_BankStatementLine bankStatementLine = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(-123, euroCurrencyId))
.build();

final I_C_Payment payment = paymentBL.newOutboundPaymentBuilder()
.adOrgId(OrgId.ANY)
Expand Down Expand Up @@ -271,10 +300,11 @@ void OneMatchingPaymentExists_SoItIsLinked()

final BPartnerId customerId = createCustomer();

final I_C_BankStatementLine bsl = createBankStatementLine(
BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()),
customerId,
Money.of(-123, euroCurrencyId));
final I_C_BankStatementLine bsl = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(-123, euroCurrencyId))
.build();

final I_C_Payment payment = paymentBL.newOutboundPaymentBuilder()
.adOrgId(OrgId.ANY)
Expand Down Expand Up @@ -312,10 +342,11 @@ void TwoIdenticalPaymentsExist_SoLineHasNoPaymentLinked()

final BPartnerId customerId = createCustomer();

final I_C_BankStatementLine bsl = createBankStatementLine(
BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()),
customerId,
Money.of(-123, euroCurrencyId));
final I_C_BankStatementLine bsl = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(-123, euroCurrencyId))
.build();

//
// create 2 identical payments
Expand Down Expand Up @@ -375,10 +406,11 @@ void OneInboundBankStatementLine_PaymentIsCreated()

final BPartnerId customerId = createCustomer();

final I_C_BankStatementLine bsl = createBankStatementLine(
BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()),
customerId,
Money.of(123, euroCurrencyId));
final I_C_BankStatementLine bsl = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(123, euroCurrencyId))
.build();

//
// call tested method
Expand All @@ -403,10 +435,11 @@ void OneOutboundBankStatementLine_PaymentIsCreated()

final BPartnerId customerId = createCustomer();

final I_C_BankStatementLine bsl = createBankStatementLine(
BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()),
customerId,
Money.of(-123, euroCurrencyId));
final I_C_BankStatementLine bsl = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(-123, euroCurrencyId))
.build();

//
// call tested method
Expand All @@ -423,4 +456,68 @@ void OneOutboundBankStatementLine_PaymentIsCreated()
}
}
}

@Nested
public class linkMultiPayments
{
@Nested
public class onePayment
{
@Test
public void bankStatementLine_NotProcessed()
{
final boolean bankStatementLineProcessed = false;
test(bankStatementLineProcessed);
}

@Test
public void bankStatementLine_Processed()
{
final boolean bankStatementLineProcessed = true;
test(bankStatementLineProcessed);
}

private void test(final boolean bankStatementLineProcessed)
{
final I_C_BankStatement bankStatement = createBankStatement(euroOrgBankAccountId);
final BPartnerId customerId = createCustomer();
final I_C_BankStatementLine bsl = bankStatementLine()
.bankStatementId(BankStatementId.ofRepoId(bankStatement.getC_BankStatement_ID()))
.bpartnerId(customerId)
.stmtAmt(Money.of(-123, euroCurrencyId))
.processed(bankStatementLineProcessed)
.build();

final I_C_Payment payment = paymentBL.newOutboundPaymentBuilder()
.adOrgId(OrgId.ANY)
.bpartnerId(customerId)
.orgBankAccountId(euroOrgBankAccountId)
.currencyId(euroCurrencyId)
.payAmt(new BigDecimal("123"))
.dateAcct(statementDate)
.dateTrx(statementDate)
.description("test")
.tenderType(TenderType.DirectDeposit)
.createAndProcess();
final PaymentId paymentId = PaymentId.ofRepoId(payment.getC_Payment_ID());

final BankStatementLineMultiPaymentLinkResult result = bankStatementPaymentBL.linkMultiPayments(BankStatementLineMultiPaymentLinkRequest.builder()
.bankStatementLineId(BankStatementLineId.ofRepoId(bsl.getC_BankStatementLine_ID()))
.paymentToLink(PaymentToLink.builder()
.paymentId(paymentId)
.statementLineAmt(Amount.of(-123, CurrencyCode.EUR))
.build())
.build());

assertThat(result.getPayments()).hasSize(1);
final PaymentLinkResult paymentLinkResult = result.getPayments().get(0);
assertThat(paymentLinkResult.getPaymentId()).isEqualTo(paymentId);
assertThat(paymentLinkResult.getStatementTrxAmt()).isEqualTo(Money.of(-123, euroCurrencyId));

final I_C_BankStatementLine_Ref lineRef = InterfaceWrapperHelper.load(paymentLinkResult.getBankStatementLineRefId(), I_C_BankStatementLine_Ref.class);
assertThat(lineRef.isProcessed()).isEqualTo(bankStatementLineProcessed);
}

}
}
}

0 comments on commit 77f1bb9

Please sign in to comment.