Search in sources :

Example 1 with InvoiceGeneratorSupplyChain

use of com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method createInvoiceGenerator.

@Override
public InvoiceGenerator createInvoiceGenerator(SaleOrder saleOrder, boolean isRefund) throws AxelorException {
    if (saleOrder.getCurrency() == null) {
        throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), saleOrder.getSaleOrderSeq());
    }
    // do not use invoiced partner if the option is disabled
    if (!appSupplychainService.getAppSupplychain().getActivatePartnerRelations()) {
        saleOrder.setInvoicedPartner(null);
    }
    return new InvoiceGeneratorSupplyChain(saleOrder, isRefund) {

        @Override
        public Invoice generate() throws AxelorException {
            Invoice invoice = super.createInvoiceHeader();
            invoice.setHeadOfficeAddress(saleOrder.getClientPartner().getHeadOfficeAddress());
            return invoice;
        }
    };
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) InvoiceGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain)

Example 2 with InvoiceGeneratorSupplyChain

use of com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain in project axelor-open-suite by axelor.

the class StockMoveInvoiceServiceImpl method createInvoiceFromOrderlessStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createInvoiceFromOrderlessStockMove(StockMove stockMove, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    int stockMoveType = stockMove.getTypeSelect();
    int invoiceOperationType;
    if (stockMove.getIsReversion()) {
        if (stockMoveType == StockMoveRepository.TYPE_INCOMING) {
            invoiceOperationType = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
        } else if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
            invoiceOperationType = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
        } else {
            return null;
        }
    } else {
        if (stockMoveType == StockMoveRepository.TYPE_INCOMING) {
            invoiceOperationType = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
        } else if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
            invoiceOperationType = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
        } else {
            return null;
        }
    }
    // do not use invoiced partner if the option is disabled
    if (!appSupplychainService.getAppSupplychain().getActivatePartnerRelations()) {
        stockMove.setInvoicedPartner(null);
    }
    InvoiceGenerator invoiceGenerator = new InvoiceGeneratorSupplyChain(stockMove, invoiceOperationType) {

        @Override
        public Invoice generate() throws AxelorException {
            return super.createInvoiceHeader();
        }
    };
    Invoice invoice = invoiceGenerator.generate();
    invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, stockMove, stockMove.getStockMoveLineList(), qtyToInvoiceMap));
    if (invoice != null) {
        this.extendInternalReference(stockMove, invoice);
        invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
        if (stockMoveType == StockMoveRepository.TYPE_OUTGOING) {
            invoice.setHeadOfficeAddress(stockMove.getPartner().getHeadOfficeAddress());
        }
        invoiceRepository.save(invoice);
        if (invoice != null) {
            Set<StockMove> stockMoveSet = invoice.getStockMoveSet();
            if (stockMoveSet == null) {
                stockMoveSet = new HashSet<>();
                invoice.setStockMoveSet(stockMoveSet);
            }
            stockMoveSet.add(stockMove);
        }
        invoiceRepository.save(invoice);
    }
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) InvoiceGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain) Transactional(com.google.inject.persist.Transactional)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)2 InvoiceGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceGeneratorSupplyChain)2 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)1 StockMove (com.axelor.apps.stock.db.StockMove)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1