use of com.axelor.apps.account.db.InvoicePayment in project axelor-open-suite by axelor.
the class InvoiceServiceImpl method removeBecauseOfAmountRemaining.
protected boolean removeBecauseOfAmountRemaining(Invoice invoice, Invoice candidateAdvancePayment) throws AxelorException {
List<InvoicePayment> invoicePayments = candidateAdvancePayment.getInvoicePaymentList();
// no payment : remove the candidate invoice
if (invoicePayments == null || invoicePayments.isEmpty()) {
return true;
}
// imputed
if (!accountConfigService.getAccountConfig(invoice.getCompany()).getGenerateMoveForInvoicePayment()) {
for (InvoicePayment invoicePayment : invoicePayments) {
if (invoicePayment.getImputedBy() == null) {
return false;
}
}
return true;
}
// else we check the remaining amount
for (InvoicePayment invoicePayment : invoicePayments) {
Move move = invoicePayment.getMove();
if (move == null) {
continue;
}
List<MoveLine> moveLineList = move.getMoveLineList();
if (moveLineList == null || moveLineList.isEmpty()) {
continue;
}
for (MoveLine moveLine : moveLineList) {
BigDecimal amountRemaining = moveLine.getAmountRemaining();
if (amountRemaining != null && amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
return false;
}
}
}
return true;
}
Aggregations