Search in sources :

Example 1 with StockRules

use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.

the class StockLocationServiceImpl method getBadStockLocationLineId.

public List<Long> getBadStockLocationLineId() {
    List<StockLocationLine> stockLocationLineList = Beans.get(StockLocationLineRepository.class).all().filter("self.stockLocation.typeSelect = 1 OR self.stockLocation.typeSelect = 2").fetch();
    List<Long> idList = new ArrayList<>();
    StockRulesRepository stockRulesRepository = Beans.get(StockRulesRepository.class);
    for (StockLocationLine stockLocationLine : stockLocationLineList) {
        StockRules stockRules = stockRulesRepository.all().filter("self.stockLocation = ?1 AND self.product = ?2", stockLocationLine.getStockLocation(), stockLocationLine.getProduct()).fetchOne();
        if (stockRules != null && stockLocationLine.getFutureQty().compareTo(stockRules.getMinQty()) < 0) {
            idList.add(stockLocationLine.getId());
        }
    }
    if (idList.isEmpty()) {
        idList.add(0L);
    }
    return idList;
}
Also used : StockRulesRepository(com.axelor.apps.stock.db.repo.StockRulesRepository) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) ArrayList(java.util.ArrayList) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) StockRules(com.axelor.apps.stock.db.StockRules)

Example 2 with StockRules

use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.

the class StockLocationLineServiceImpl method checkStockMax.

protected void checkStockMax(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type, BigDecimal baseQty) throws AxelorException {
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null || !stockRules.getUseMaxQty()) {
        return;
    }
    if (baseQty.add(qty).compareTo(stockRules.getMaxQty()) > 0) {
        throw new AxelorException(stockLocationLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_3), stockLocationLine.getProduct().getName(), stockLocationLine.getProduct().getCode());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) StockRules(com.axelor.apps.stock.db.StockRules)

Example 3 with StockRules

use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.

the class StockRulesServiceImpl method generatePurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generatePurchaseOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    // TODO à supprimer après suppression des variantes
    if (stockLocation == null) {
        return;
    }
    StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null) {
        return;
    }
    if (this.useMinStockRules(stockLocationLine, stockRules, qty, type)) {
        if (stockRules.getOrderAlertSelect() == StockRulesRepository.ORDER_ALERT_ALERT) {
        // TODO
        }
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) StockRules(com.axelor.apps.stock.db.StockRules) Transactional(com.google.inject.persist.Transactional)

Example 4 with StockRules

use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.

the class MrpLineServiceImpl method setMrpLineQty.

protected MrpLine setMrpLineQty(MrpLine mrpLine, Product product, StockLocation stockLocation) {
    StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, StockRulesRepository.TYPE_FUTURE, StockRulesRepository.USE_CASE_USED_FOR_MRP);
    if (stockRules != null) {
        mrpLine.setMinQty(stockRules.getMinQty());
        mrpLine.setIdealQty(stockRules.getIdealQty());
        mrpLine.setReOrderQty(stockRules.getReOrderQty());
    }
    return mrpLine;
}
Also used : StockRules(com.axelor.apps.stock.db.StockRules)

Example 5 with StockRules

use of com.axelor.apps.stock.db.StockRules in project axelor-open-suite by axelor.

the class StockRulesServiceSupplychainImpl method generatePurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generatePurchaseOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        super.generatePurchaseOrder(product, qty, stockLocationLine, type);
        return;
    }
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    // TODO à supprimer après suppression des variantes
    if (stockLocation == null) {
        return;
    }
    StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null) {
        return;
    }
    if (this.useMinStockRules(stockLocationLine, stockRules, qty, type)) {
        if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_ALERT)) {
            this.generateAndSendMessage(stockRules);
        } else if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_PURCHASE_ORDER)) {
            BigDecimal minReorderQty = getDefaultSupplierMinQty(product);
            BigDecimal qtyToOrder = this.getQtyToOrder(qty, stockLocationLine, type, stockRules, minReorderQty);
            Partner supplierPartner = product.getDefaultSupplierPartner();
            if (supplierPartner != null) {
                Company company = stockLocation.getCompany();
                LocalDate today = Beans.get(AppBaseService.class).getTodayDate(company);
                PurchaseOrderSupplychainService purchaseOrderSupplychainService = Beans.get(PurchaseOrderSupplychainService.class);
                PurchaseOrder purchaseOrder = purchaseOrderRepo.save(purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), company, null, supplierPartner.getCurrency(), today.plusDays(supplierPartner.getDeliveryDelay()), stockRules.getName(), null, stockLocation, today, Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, null));
                purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, null, null, qtyToOrder, product.getUnit()));
                Beans.get(PurchaseOrderService.class).computePurchaseOrder(purchaseOrder);
                purchaseOrderRepo.save(purchaseOrder);
                if (stockRules.getAlert()) {
                    this.generateAndSendMessage(stockRules);
                }
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) StockRules(com.axelor.apps.stock.db.StockRules) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockRules (com.axelor.apps.stock.db.StockRules)7 StockLocation (com.axelor.apps.stock.db.StockLocation)5 Transactional (com.google.inject.persist.Transactional)3 Company (com.axelor.apps.base.db.Company)2 BigDecimal (java.math.BigDecimal)2 Partner (com.axelor.apps.base.db.Partner)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)1 StockRulesRepository (com.axelor.apps.stock.db.repo.StockRulesRepository)1 MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)1 AxelorException (com.axelor.exception.AxelorException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1