Search in sources :

Example 26 with Unit

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

the class MrpServiceImpl method createSaleForecastMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createSaleForecastMrpLines(Mrp mrp, MrpForecast mrpForecast, MrpLineType saleForecastMrpLineType) throws AxelorException {
    LocalDate maturityDate = mrpForecast.getForecastDate();
    if (maturityDate != null && !maturityDate.isBefore(today) && this.isBeforeEndDate(maturityDate)) {
        Unit unit = mrpForecast.getProduct().getUnit();
        BigDecimal qty = mrpForecast.getQty();
        if (!unit.equals(mrpForecast.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(mrpForecast.getUnit(), unit, qty, qty.scale(), mrpForecast.getProduct());
        }
        MrpLine mrpLine = this.createMrpLine(mrp, mrpForecast.getProduct(), saleForecastMrpLineType, qty, maturityDate, BigDecimal.ZERO, mrpForecast.getStockLocation(), mrpForecast);
        if (mrpLine != null) {
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 27 with Unit

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

the class MrpServiceImpl method createPurchaseMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createPurchaseMrpLines(Mrp mrp, PurchaseOrderLine purchaseOrderLine, MrpLineType purchaseOrderMrpLineType) throws AxelorException {
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    LocalDate maturityDate = purchaseOrderLine.getEstimatedDelivDate();
    if (maturityDate == null) {
        maturityDate = purchaseOrder.getDeliveryDate();
    }
    if (maturityDate == null) {
        maturityDate = purchaseOrderLine.getDesiredDelivDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, purchaseOrderMrpLineType);
    if (this.isBeforeEndDate(maturityDate) || purchaseOrderMrpLineType.getIgnoreEndDate()) {
        Unit unit = purchaseOrderLine.getProduct().getUnit();
        BigDecimal qty = purchaseOrderLine.getQty().subtract(purchaseOrderLine.getReceivedQty());
        if (!unit.equals(purchaseOrderLine.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), purchaseOrderLine.getProduct());
        }
        MrpLine mrpLine = this.createMrpLine(mrp, purchaseOrderLine.getProduct(), purchaseOrderMrpLineType, qty, maturityDate, BigDecimal.ZERO, purchaseOrder.getStockLocation(), purchaseOrderLine);
        if (mrpLine != null) {
            mrpLine.setSupplierPartner(purchaseOrder.getSupplierPartner());
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) MrpLine(com.axelor.apps.supplychain.db.MrpLine) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 28 with Unit

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

the class MrpServiceImpl method createSaleOrderMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createSaleOrderMrpLines(Mrp mrp, SaleOrderLine saleOrderLine, MrpLineType saleOrderMrpLineType, List<Integer> statusList) throws AxelorException {
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (!this.stockLocationList.contains(saleOrder.getStockLocation())) {
        return;
    }
    if (!statusList.contains(saleOrder.getStatusSelect())) {
        return;
    }
    if (saleOrderLine.getDeliveryState() == SaleOrderLineRepository.DELIVERY_STATE_DELIVERED) {
        return;
    }
    LocalDate maturityDate = saleOrderLine.getEstimatedDelivDate();
    if (maturityDate == null) {
        maturityDate = saleOrder.getDeliveryDate();
    }
    if (maturityDate == null) {
        maturityDate = saleOrderLine.getDesiredDelivDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, saleOrderMrpLineType);
    if (this.isBeforeEndDate(maturityDate)) {
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal qty = saleOrderLine.getQty().subtract(saleOrderLine.getDeliveredQty());
        if (!unit.equals(saleOrderLine.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(saleOrderLine.getUnit(), unit, qty, saleOrderLine.getQty().scale(), saleOrderLine.getProduct());
        }
        MrpLine mrpLine = this.createMrpLine(mrp, saleOrderLine.getProduct(), saleOrderMrpLineType, qty, maturityDate, BigDecimal.ZERO, saleOrder.getStockLocation(), saleOrderLine);
        if (mrpLine != null) {
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 29 with Unit

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

the class ProductStockLocationServiceImpl method getAvailableQty.

protected BigDecimal getAvailableQty(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.getAvailableStockForAProduct(product.getId(), companyId, stockLocationId);
    List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
    // Compute
    BigDecimal sumAvailableQty = BigDecimal.ZERO;
    if (!stockLocationLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal productAvailableQty = stockLocationLine.getCurrentQty();
            unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, productAvailableQty, productAvailableQty.scale(), product);
            sumAvailableQty = sumAvailableQty.add(productAvailableQty);
        }
    }
    return sumAvailableQty;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 30 with Unit

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

the class PurchaseOrderServiceImpl method updateCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateCostPrice(PurchaseOrder purchaseOrder) throws AxelorException {
    if (purchaseOrder.getPurchaseOrderLineList() != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            Product product = purchaseOrderLine.getProduct();
            if (product != null) {
                BigDecimal lastPurchasePrice = (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()) ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice();
                lastPurchasePrice = currencyService.getAmountCurrencyConvertedAtDate(purchaseOrder.getCurrency(), purchaseOrder.getCompany().getCurrency(), lastPurchasePrice, currencyService.getDateToConvert(null));
                productCompanyService.set(product, "lastPurchasePrice", lastPurchasePrice, purchaseOrder.getCompany());
                LocalDate lastPurchaseDate = Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
                productCompanyService.set(product, "lastPurchaseDate", lastPurchaseDate, purchaseOrder.getCompany());
                if ((Boolean) productCompanyService.get(product, "defShipCoefByPartner", purchaseOrder.getCompany())) {
                    Unit productPurchaseUnit = (Unit) productCompanyService.get(product, "purchasesUnit", purchaseOrder.getCompany());
                    productPurchaseUnit = productPurchaseUnit != null ? productPurchaseUnit : (Unit) productCompanyService.get(product, "unit", purchaseOrder.getCompany());
                    BigDecimal convertedQty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), productPurchaseUnit, purchaseOrderLine.getQty(), purchaseOrderLine.getQty().scale(), product);
                    BigDecimal shippingCoef = Beans.get(ShippingCoefService.class).getShippingCoefDefByPartner(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), convertedQty);
                    if (shippingCoef.compareTo(BigDecimal.ZERO) != 0) {
                        productCompanyService.set(product, "shippingCoef", shippingCoef, purchaseOrder.getCompany());
                    }
                }
                if ((Integer) productCompanyService.get(product, "costTypeSelect", purchaseOrder.getCompany()) == ProductRepository.COST_TYPE_LAST_PURCHASE_PRICE) {
                    productCompanyService.set(product, "costPrice", lastPurchasePrice, purchaseOrder.getCompany());
                    if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", purchaseOrder.getCompany())) {
                        Beans.get(ProductService.class).updateSalePrice(product, purchaseOrder.getCompany());
                    }
                }
            }
        }
        purchaseOrderRepo.save(purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) User(com.axelor.auth.db.User) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ProductService(com.axelor.apps.base.service.ProductService) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

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