Search in sources :

Example 1 with RefundInvoice

use of com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice in project axelor-open-suite by axelor.

the class InvoiceServiceImpl method createRefund.

/**
 * Créer un avoir.
 *
 * <p>Un avoir est une facture "inversée". Tout le montant sont opposés à la facture originale.
 *
 * @param invoice
 * @return
 * @throws AxelorException
 */
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createRefund(Invoice invoice) throws AxelorException {
    Invoice refund = new RefundInvoice(invoice).generate();
    invoice.addRefundInvoiceListItem(refund);
    invoiceRepo.save(invoice);
    return refund;
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Transactional(com.google.inject.persist.Transactional)

Example 2 with RefundInvoice

use of com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice in project axelor-open-suite by axelor.

the class StockMoveMultiInvoiceServiceImpl method transformToRefund.

/**
 * Change the operation type and invert all prices in the invoice.
 *
 * @param invoice an invoice
 * @return the refund invoice
 */
protected Invoice transformToRefund(Invoice invoice) throws AxelorException {
    Invoice refund = new RefundInvoice(invoice).generate();
    if (refund.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : refund.getInvoiceLineList()) {
            invoiceLine.setPrice(invoiceLine.getPrice().negate());
            invoiceLine.setPriceDiscounted(invoiceLine.getPriceDiscounted().negate());
            invoiceLine.setInTaxPrice(invoiceLine.getInTaxPrice().negate());
            invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().negate());
            invoiceLine.setInTaxTotal(invoiceLine.getInTaxTotal().negate());
            invoiceLine.setCompanyExTaxTotal(invoiceLine.getCompanyExTaxTotal().negate());
            invoiceLine.setCompanyInTaxTotal(invoiceLine.getCompanyInTaxTotal().negate());
        }
    }
    if (refund.getInvoiceLineTaxList() != null) {
        for (InvoiceLineTax invoiceLineTax : refund.getInvoiceLineTaxList()) {
            invoiceLineTax.setExTaxBase(invoiceLineTax.getExTaxBase().negate());
            invoiceLineTax.setTaxTotal(invoiceLineTax.getTaxTotal().negate());
            invoiceLineTax.setCompanyExTaxBase(invoiceLineTax.getCompanyExTaxBase().negate());
            invoiceLineTax.setInTaxTotal(invoiceLineTax.getInTaxTotal().negate());
            invoiceLineTax.setCompanyInTaxTotal(invoiceLineTax.getCompanyInTaxTotal().negate());
        }
    }
    refund.setExTaxTotal(refund.getExTaxTotal().negate());
    refund.setInTaxTotal(refund.getInTaxTotal().negate());
    refund.setCompanyExTaxTotal(refund.getCompanyExTaxTotal().negate());
    refund.setCompanyInTaxTotal(refund.getCompanyInTaxTotal().negate());
    refund.setTaxTotal(refund.getTaxTotal().negate());
    refund.setAmountRemaining(refund.getAmountRemaining().negate());
    refund.setCompanyTaxTotal(refund.getCompanyTaxTotal().negate());
    refund.setPaymentMode(InvoiceToolService.getPaymentMode(refund));
    return invoiceRepository.save(refund);
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)2 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 InvoiceLineTax (com.axelor.apps.account.db.InvoiceLineTax)1 Transactional (com.google.inject.persist.Transactional)1