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;
}
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());
}
}
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
}
}
}
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;
}
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);
}
}
}
}
}
Aggregations