Search in sources :

Example 11 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class PurchaseOrderLineServiceSupplychainImpl method createPurchaseOrderLine.

public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder, SaleOrderLine saleOrderLine) throws AxelorException {
    LOG.debug("Création d'une ligne de commande fournisseur pour le produit : {}", saleOrderLine.getProductName());
    Unit unit = null;
    BigDecimal qty = BigDecimal.ZERO;
    if (saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL) {
        if (saleOrderLine.getProduct() != null) {
            unit = saleOrderLine.getProduct().getPurchasesUnit();
        }
        qty = saleOrderLine.getQty();
        if (unit == null) {
            unit = saleOrderLine.getUnit();
        } else {
            qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
        }
    }
    PurchaseOrderLine purchaseOrderLine = super.createPurchaseOrderLine(purchaseOrder, saleOrderLine.getProduct(), saleOrderLine.getProductName(), null, qty, unit);
    purchaseOrderLine.setIsTitleLine(!(saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL));
    this.getAndComputeAnalyticDistribution(purchaseOrderLine, purchaseOrder);
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 12 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createProductStockMoveLine.

protected StockMoveLine createProductStockMoveLine(PurchaseOrderLine purchaseOrderLine, BigDecimal qty, StockMove stockMove) throws AxelorException {
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    Product product = purchaseOrderLine.getProduct();
    Unit unit = product.getUnit();
    BigDecimal priceDiscounted = purchaseOrderLine.getPriceDiscounted();
    BigDecimal companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal();
    if (purchaseOrderLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
        companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal().divide(purchaseOrderLine.getQty(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    }
    if (unit != null && !unit.equals(purchaseOrderLine.getUnit())) {
        qty = unitConversionService.convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), product);
        priceDiscounted = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        companyUnitPriceUntaxed = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), companyUnitPriceUntaxed, appBaseService.getNbDecimalDigitForUnitPrice(), product);
    }
    BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), qty);
    BigDecimal companyPurchasePrice = priceDiscounted;
    priceDiscounted = priceDiscounted.multiply(shippingCoef);
    companyUnitPriceUntaxed = companyUnitPriceUntaxed.multiply(shippingCoef);
    BigDecimal taxRate = BigDecimal.ZERO;
    TaxLine taxLine = purchaseOrderLine.getTaxLine();
    if (taxLine != null) {
        taxRate = taxLine.getValue();
    }
    if (purchaseOrderLine.getReceiptState() == 0) {
        purchaseOrderLine.setReceiptState(PurchaseOrderLineRepository.RECEIPT_STATE_NOT_RECEIVED);
    }
    return stockMoveLineServiceSupplychain.createStockMoveLine(product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qty, BigDecimal.ZERO, priceDiscounted, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, StockMoveLineService.TYPE_PURCHASES, purchaseOrder.getInAti(), taxRate, null, purchaseOrderLine);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 13 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class ProductStockLocationServiceImpl method getRequestedReservedQty.

protected BigDecimal getRequestedReservedQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
    }
    if (stockLocation != null) {
        stockLocationId = stockLocation.getId();
    }
    String query = stockLocationLineService.getStockLocationLineListForAProduct(product.getId(), companyId, stockLocationId);
    List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
    // Compute
    BigDecimal sumRequestedReservedQty = BigDecimal.ZERO;
    if (!stockLocationLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal requestedReservedQty = stockLocationLine.getRequestedReservedQty();
            requestedReservedQty = unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, requestedReservedQty, requestedReservedQty.scale(), product);
            sumRequestedReservedQty = sumRequestedReservedQty.add(requestedReservedQty);
        }
    }
    return sumRequestedReservedQty;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 14 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class ProductStockLocationServiceImpl method getSaleOrderQty.

protected BigDecimal getSaleOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
    }
    if (stockLocation != null) {
        stockLocationId = stockLocation.getId();
    }
    String query = Beans.get(SaleOrderLineServiceSupplyChain.class).getSaleOrderLineListForAProduct(product.getId(), companyId, stockLocationId);
    List<SaleOrderLine> saleOrderLineList = Beans.get(SaleOrderLineRepository.class).all().filter(query).fetch();
    // Compute
    BigDecimal sumSaleOrderQty = BigDecimal.ZERO;
    if (!saleOrderLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            BigDecimal productSaleOrderQty = saleOrderLine.getQty();
            if (saleOrderLine.getDeliveryState() == SaleOrderLineRepository.DELIVERY_STATE_PARTIALLY_DELIVERED) {
                productSaleOrderQty = productSaleOrderQty.subtract(saleOrderLine.getDeliveredQty());
            }
            productSaleOrderQty = unitConversionService.convert(saleOrderLine.getUnit(), unitConversion, productSaleOrderQty, productSaleOrderQty.scale(), product);
            sumSaleOrderQty = sumSaleOrderQty.add(productSaleOrderQty);
        }
    }
    return sumSaleOrderQty;
}
Also used : SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 15 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class ProductStockLocationServiceImpl method getPurchaseOrderQty.

protected BigDecimal getPurchaseOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
    }
    if (stockLocation != null) {
        stockLocationId = stockLocation.getId();
    }
    String query = Beans.get(PurchaseOrderStockService.class).getPurchaseOrderLineListForAProduct(product.getId(), companyId, stockLocationId);
    List<PurchaseOrderLine> purchaseOrderLineList = Beans.get(PurchaseOrderLineRepository.class).all().filter(query).fetch();
    // Compute
    BigDecimal sumPurchaseOrderQty = BigDecimal.ZERO;
    if (!purchaseOrderLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            BigDecimal productPurchaseOrderQty = purchaseOrderLine.getQty();
            if (purchaseOrderLine.getReceiptState() == PurchaseOrderLineRepository.RECEIPT_STATE_PARTIALLY_RECEIVED) {
                productPurchaseOrderQty = productPurchaseOrderQty.subtract(purchaseOrderLine.getReceivedQty());
            }
            productPurchaseOrderQty = unitConversionService.convert(purchaseOrderLine.getUnit(), unitConversion, productPurchaseOrderQty, productPurchaseOrderQty.scale(), product);
            sumPurchaseOrderQty = sumPurchaseOrderQty.add(productPurchaseOrderQty);
        }
    }
    return sumPurchaseOrderQty;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

Unit (com.axelor.apps.base.db.Unit)45 BigDecimal (java.math.BigDecimal)38 Product (com.axelor.apps.base.db.Product)19 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)11 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)9 Company (com.axelor.apps.base.db.Company)8 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)8 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 StockLocation (com.axelor.apps.stock.db.StockLocation)6 StockMove (com.axelor.apps.stock.db.StockMove)6 LocalDate (java.time.LocalDate)6 List (java.util.List)6 ProdProduct (com.axelor.apps.production.db.ProdProduct)5 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)5 ArrayList (java.util.ArrayList)5 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)4