Skip to content

Commit

Permalink
Carry on Invoice to Payment when Payment is created from BankStatemen…
Browse files Browse the repository at this point in the history
…tLine

#6547
  • Loading branch information
TheBestPessimist committed May 5, 2020
1 parent 0c5481e commit 2df0306
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import de.metas.document.engine.DocStatus;
import de.metas.document.engine.IDocument;
import de.metas.document.engine.IDocumentBL;
import de.metas.invoice.InvoiceId;
import de.metas.money.CurrencyId;
import de.metas.money.Money;
import de.metas.money.MoneyService;
Expand Down Expand Up @@ -92,6 +93,7 @@ public void findOrCreateSinglePaymentAndLinkIfPossible(
}

final Set<PaymentId> eligiblePaymentIds = findEligiblePaymentIds(bankStatementLine, bpartnerId, 2);
//noinspection StatementWithEmptyBody
if (eligiblePaymentIds.size() > 1)
{
// Don't create a new Payment and don't link any of the existing payments if there are multiple payments found.
Expand Down Expand Up @@ -160,22 +162,30 @@ private I_C_Payment createPayment(
final boolean inboundPayment = statementAmt.signum() >= 0;
final Money payAmount = statementAmt.negateIf(!inboundPayment);

final InvoiceId invoiceId = InvoiceId.ofRepoIdOrNull(bankStatementLine.getC_Invoice_ID());

final TenderType tenderType = paymentBL.getTenderType(BPartnerBankAccountId.ofRepoId(bpartnerId, orgBankAccountId.getRepoId()));

final DefaultPaymentBuilder paymentBuilder = inboundPayment
? paymentBL.newInboundReceiptBuilder()
: paymentBL.newOutboundPaymentBuilder();

return paymentBuilder
paymentBuilder
.adOrgId(orgId)
.bpartnerId(bpartnerId)
.orgBankAccountId(orgBankAccountId)
.currencyId(payAmount.getCurrencyId())
.payAmt(payAmount.toBigDecimal())
.dateAcct(acctLineDate)
.dateTrx(acctLineDate) // Note: DateTrx should be the same as Line.DateAcct, and not Line.StatementDate.
.tenderType(tenderType)
.createDraft(); // note: don't complete the payment now, else onComplete interceptors might link this payment to a different Bank Statement Line.
.tenderType(tenderType);

if (invoiceId != null)
{
paymentBuilder.invoiceId(invoiceId);
}

return paymentBuilder.createDraft(); // note: don't complete the payment now, else onComplete interceptors might link this payment to a different Bank Statement Line.
}

@Override
Expand Down

0 comments on commit 2df0306

Please sign in to comment.