Search in sources :

Example 61 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method computeFromOrder.

protected StockMoveLine computeFromOrder(StockMoveLine stockMoveLine, StockMove stockMove) throws AxelorException {
    BigDecimal unitPriceUntaxed = stockMoveLine.getUnitPriceUntaxed();
    BigDecimal unitPriceTaxed = stockMoveLine.getUnitPriceTaxed();
    Unit orderUnit = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
        if (saleOrderLine == null) {
            // log the exception
            TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_SALE_ORDER, stockMove.getOriginId(), stockMove.getName()));
        } else {
            unitPriceUntaxed = saleOrderLine.getPriceDiscounted();
            unitPriceTaxed = saleOrderLine.getInTaxPrice();
            orderUnit = saleOrderLine.getUnit();
        }
    } else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
        if (purchaseOrderLine == null) {
            // log the exception
            TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_PURCHASE_ORDER, stockMove.getOriginId(), stockMove.getName()));
        } else {
            unitPriceUntaxed = purchaseOrderLine.getPrice();
            unitPriceTaxed = purchaseOrderLine.getInTaxPrice();
            orderUnit = purchaseOrderLine.getUnit();
        }
    }
    stockMoveLine.setUnitPriceUntaxed(unitPriceUntaxed);
    stockMoveLine.setUnitPriceTaxed(unitPriceTaxed);
    Unit stockUnit = getStockUnit(stockMoveLine);
    return convertUnitPrice(stockMoveLine, orderUnit, stockUnit);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) Unit(com.axelor.apps.base.db.Unit) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 62 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.

@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
    if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
        return null;
    }
    if (stockMoveLineList.size() == 1) {
        return stockMoveLineList.get(0);
    }
    StockMove stockMove = stockMoveLineList.get(0).getStockMove();
    SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
    Product product;
    String productName;
    String description;
    BigDecimal quantity = BigDecimal.ZERO;
    Unit unit;
    if (saleOrderLine != null) {
        product = saleOrderLine.getProduct();
        productName = saleOrderLine.getProductName();
        description = saleOrderLine.getDescription();
        unit = saleOrderLine.getUnit();
    } else if (purchaseOrderLine != null) {
        product = purchaseOrderLine.getProduct();
        productName = purchaseOrderLine.getProductName();
        description = purchaseOrderLine.getDescription();
        unit = purchaseOrderLine.getUnit();
    } else {
        // shouldn't ever happen or you misused this function
        return null;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        quantity = quantity.add(stockMoveLine.getRealQty());
    }
    StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
    generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
    generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
    generatedStockMoveLine.setIsMergedStockMoveLine(true);
    return generatedStockMoveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMove(com.axelor.apps.stock.db.StockMove) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 63 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method setProductInfo.

/**
 * This implementation copy fields from sale order line and purchase order line if the link
 * exists.
 *
 * @param stockMove
 * @param stockMoveLine
 * @param company
 */
@Override
public void setProductInfo(StockMove stockMove, StockMoveLine stockMoveLine, Company company) throws AxelorException {
    if (!Beans.get(AppBaseService.class).isApp("supplychain")) {
        super.setProductInfo(stockMove, stockMoveLine, company);
        return;
    }
    Preconditions.checkNotNull(stockMoveLine);
    Preconditions.checkNotNull(company);
    Product product = stockMoveLine.getProduct();
    if (product == null) {
        return;
    }
    super.setProductInfo(stockMove, stockMoveLine, company);
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
    if (saleOrderLine != null) {
        setProductInfoFromSaleOrder(stockMoveLine, saleOrderLine);
    }
    if (purchaseOrderLine != null) {
        setProductInfoFromPurchaseOrder(stockMoveLine, purchaseOrderLine);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 64 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class StockMoveInvoiceServiceImpl method getConsolidatedStockMoveLineList.

/**
 * Get a list of stock move lines consolidated by parent line (sale or purchase order).
 *
 * @param stockMoveLineList
 * @return
 * @throws AxelorException
 */
private List<StockMoveLine> getConsolidatedStockMoveLineList(List<StockMoveLine> stockMoveLineList) throws AxelorException {
    Map<SaleOrderLine, List<StockMoveLine>> stockMoveLineSaleMap = new LinkedHashMap<>();
    Map<PurchaseOrderLine, List<StockMoveLine>> stockMoveLinePurchaseMap = new LinkedHashMap<>();
    List<StockMoveLine> resultList = new ArrayList<>();
    List<StockMoveLine> list;
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        if (stockMoveLine.getSaleOrderLine() != null) {
            list = stockMoveLineSaleMap.get(stockMoveLine.getSaleOrderLine());
            if (list == null) {
                list = new ArrayList<>();
                stockMoveLineSaleMap.put(stockMoveLine.getSaleOrderLine(), list);
            }
            list.add(stockMoveLine);
        } else if (stockMoveLine.getPurchaseOrderLine() != null) {
            list = stockMoveLinePurchaseMap.get(stockMoveLine.getPurchaseOrderLine());
            if (list == null) {
                list = new ArrayList<>();
                stockMoveLinePurchaseMap.put(stockMoveLine.getPurchaseOrderLine(), list);
            }
            list.add(stockMoveLine);
        } else {
            // if the stock move line does not have a parent line (sale or purchase order line)
            resultList.add(stockMoveLine);
        }
    }
    for (List<StockMoveLine> stockMoveLines : stockMoveLineSaleMap.values()) {
        resultList.add(stockMoveLineServiceSupplychain.getMergedStockMoveLine(stockMoveLines));
    }
    for (List<StockMoveLine> stockMoveLines : stockMoveLinePurchaseMap.values()) {
        resultList.add(stockMoveLineServiceSupplychain.getMergedStockMoveLine(stockMoveLines));
    }
    return resultList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ArrayList(java.util.ArrayList) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LinkedHashMap(java.util.LinkedHashMap)

Example 65 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine 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

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5