Search in sources :

Example 1 with InvoiceLineGeneratorSupplyChain

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

the class InvoicingProjectService method createInvoiceLine.

public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, int priority) throws AxelorException {
    Product product = purchaseOrderLine.getProduct();
    InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), priority, false, null, purchaseOrderLine, null) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product)

Example 2 with InvoiceLineGeneratorSupplyChain

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

the class PurchaseOrderInvoiceServiceImpl method createInvoiceLine.

public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine, BigDecimal qtyToInvoice) throws AxelorException {
    Product product = purchaseOrderLine.getProduct();
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qtyToInvoice, purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Example 3 with InvoiceLineGeneratorSupplyChain

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

the class SaleOrderInvoiceServiceImpl method createInvoiceLine.

@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, SaleOrderLine saleOrderLine, BigDecimal qtyToInvoice) throws AxelorException {
    Product product = saleOrderLine.getProduct();
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, saleOrderLine.getProductName(), saleOrderLine.getDescription(), qtyToInvoice, saleOrderLine.getUnit(), saleOrderLine.getSequence(), false, saleOrderLine, null, null) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Example 4 with InvoiceLineGeneratorSupplyChain

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

the class PurchaseOrderInvoiceServiceImpl method createInvoiceLine.

@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
    Product product = purchaseOrderLine.getProduct();
    InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product)

Example 5 with InvoiceLineGeneratorSupplyChain

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

the class StockMoveInvoiceServiceImpl method createInvoiceLine.

@Override
public InvoiceLine createInvoiceLine(Invoice invoice, StockMoveLine stockMoveLine, BigDecimal qty) throws AxelorException {
    Product product = stockMoveLine.getProduct();
    boolean isTitleLine = false;
    int sequence = InvoiceLineGenerator.DEFAULT_SEQUENCE;
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
    if (saleOrderLine != null) {
        sequence = saleOrderLine.getSequence();
    } else if (purchaseOrderLine != null) {
        if (purchaseOrderLine.getIsTitleLine()) {
            isTitleLine = true;
        }
        sequence = purchaseOrderLine.getSequence();
    }
    // do not create lines with no qties
    if ((qty == null || qty.signum() == 0 || stockMoveLine.getRealQty().signum() == 0) && !isTitleLine) {
        return null;
    }
    if (product == null && !isTitleLine) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_1), stockMoveLine.getStockMove().getStockMoveSeq());
    }
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, stockMoveLine.getProductName(), stockMoveLine.getDescription(), qty, stockMoveLine.getUnit(), sequence, false, stockMoveLine.getSaleOrderLine(), stockMoveLine.getPurchaseOrderLine(), stockMoveLine) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
    InvoiceLine invoiceLine = null;
    if (invoiceLines != null && !invoiceLines.isEmpty()) {
        invoiceLine = invoiceLines.get(0);
        if (!stockMoveLine.getIsMergedStockMoveLine()) {
            // not a consolidated line so we can set the reference.
            invoiceLine.setStockMoveLine(stockMoveLine);
        } else {
            // set the reference to a correct stock move line by following either the sale order line or
            // purchase order line. We cannot have a consolidated line without purchase order line or
            // sale order line reference
            StockMoveLine nonConsolidatedStockMoveLine = null;
            StockMove stockMove = stockMoveLine.getStockMove();
            if (saleOrderLine != null) {
                nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.saleOrderLine.id = :saleOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("saleOrderLineId", saleOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
            } else if (purchaseOrderLine != null) {
                nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.purchaseOrderLine.id = :purchaseOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("purchaseOrderLineId", purchaseOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
            }
            invoiceLine.setStockMoveLine(nonConsolidatedStockMoveLine);
            deleteConsolidatedStockMoveLine(stockMoveLine);
        }
    }
    return invoiceLine;
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)7 Product (com.axelor.apps.base.db.Product)7 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)7 ArrayList (java.util.ArrayList)7 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)5 AxelorException (com.axelor.exception.AxelorException)2 Company (com.axelor.apps.base.db.Company)1 PriceList (com.axelor.apps.base.db.PriceList)1 PriceListLine (com.axelor.apps.base.db.PriceListLine)1 PartnerPriceListService (com.axelor.apps.base.service.PartnerPriceListService)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1