use of com.axelor.apps.account.db.AccountConfig in project axelor-open-suite by axelor.
the class MoveExcessPaymentService method getExcessPayment.
/**
* Méthode permettant de récupérer les trop-perçus et une facture
*
* @param invoice Une facture
* @return
* @throws AxelorException
*/
public List<MoveLine> getExcessPayment(Invoice invoice) throws AxelorException {
Company company = invoice.getCompany();
AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
// get advance payments
List<MoveLine> advancePaymentMoveLines = Beans.get(InvoiceService.class).getMoveLinesFromAdvancePayments(invoice);
MoveLine moveLine = getOrignalInvoiceMoveLine(invoice);
if (moveLine != null) {
advancePaymentMoveLines.add(moveLine);
}
if (accountConfig.getAutoReconcileOnInvoice()) {
List<MoveLine> creditMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.credit > 0 and self.amountRemaining > 0" + " AND self.partner = ?5 ORDER BY self.date ASC", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, invoice.getPartner()).fetch();
log.debug("Nombre de trop-perçus à imputer sur la facture récupéré : {}", creditMoveLines.size());
advancePaymentMoveLines.addAll(creditMoveLines);
}
// remove duplicates
advancePaymentMoveLines = advancePaymentMoveLines.stream().distinct().collect(Collectors.toList());
return advancePaymentMoveLines;
}
Aggregations