Search in sources :

Example 36 with StockLocation

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

the class ProductController method setIndicatorsOfProduct.

public void setIndicatorsOfProduct(ActionRequest request, ActionResponse response) {
    try {
        Map<String, Long> mapId = Beans.get(ProjectedStockService.class).getProductIdCompanyIdStockLocationIdFromContext(request.getContext());
        if (mapId == null) {
            return;
        }
        Context context = request.getContext();
        Long productId = mapId.get("productId");
        Long companyId = mapId.get("companyId");
        Long stockLocationId = mapId.get("stockLocationId");
        if (companyId == 0L && stockLocationId != 0L) {
            stockLocationId = 0L;
        } else if (companyId != 0L && stockLocationId != 0L) {
            StockLocation sl = Beans.get(StockLocationRepository.class).find(stockLocationId);
            if (sl != null && sl.getCompany() != null && sl.getCompany().getId() != companyId) {
                stockLocationId = 0L;
                response.setValue("stockLocation", null);
                context.put("$stockLocation", null);
            }
        }
        Map<String, Object> map = Beans.get(ProductStockLocationService.class).computeIndicators(productId, companyId, stockLocationId);
        response.setValues(map);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockLocation(com.axelor.apps.stock.db.StockLocation) ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) ProductStockLocationService(com.axelor.apps.supplychain.service.ProductStockLocationService)

Example 37 with StockLocation

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

the class ProductController method findAllSubLocation.

@SuppressWarnings("unchecked")
public void findAllSubLocation(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Long stockLocationId = 0L;
    Long companyId = 0L;
    LinkedHashMap<String, Object> companyHashMap = (LinkedHashMap<String, Object>) context.get("company");
    if (companyHashMap != null) {
        companyId = Long.valueOf(companyHashMap.get("id").toString());
    }
    LinkedHashMap<String, Object> stockLocationHashMap = (LinkedHashMap<String, Object>) context.get("stockLocation");
    if (stockLocationHashMap != null) {
        stockLocationId = Long.valueOf(stockLocationHashMap.get("id").toString());
    }
    if (companyId != 0L && stockLocationId != 0L) {
        StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(stockLocationId);
        if (stockLocation != null && stockLocation.getCompany().getId() == companyId) {
            List<Long> stockLocationIdList = Beans.get(StockLocationService.class).getAllLocationAndSubLocationId(stockLocation, false);
            response.setValue("$stockLocationIdList", stockLocationIdList);
            return;
        }
    }
    response.setValue("$stockLocationIdList", Arrays.asList(0L));
}
Also used : Context(com.axelor.rpc.Context) ProductStockLocationService(com.axelor.apps.supplychain.service.ProductStockLocationService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with StockLocation

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

the class MrpForecastController method generateMrpForecast.

@SuppressWarnings("unchecked")
public void generateMrpForecast(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
    LinkedHashMap<String, Object> periodMap = (LinkedHashMap<String, Object>) sopLineMap.get("period");
    Period period = Beans.get(PeriodRepository.class).find(Long.parseLong(periodMap.get("id").toString()));
    ArrayList<LinkedHashMap<String, Object>> mrpForecastList = (ArrayList<LinkedHashMap<String, Object>>) context.get("mrpForecasts");
    LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) context.get("stockLocation");
    StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(Long.parseLong(stockLocationMap.get("id").toString()));
    if (mrpForecastList != null && !mrpForecastList.isEmpty()) {
        mrpForecastProductionService.generateMrpForecast(period, mrpForecastList, stockLocation, MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP);
    }
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) PeriodRepository(com.axelor.apps.base.db.repo.PeriodRepository) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) LinkedHashMap(java.util.LinkedHashMap)

Example 39 with StockLocation

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

the class ManufOrderServiceImpl method merge.

@Transactional(rollbackOn = { Exception.class })
public void merge(List<Long> ids) throws AxelorException {
    if (!canMerge(ids)) {
        throw new AxelorException(ManufOrder.class, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.MANUF_ORDER_NO_GENERATION));
    }
    List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
    /* Init all the necessary values to create the new Manuf Order */
    Product product = manufOrderList.get(0).getProduct();
    StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
    Company company = manufOrderList.get(0).getCompany();
    BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
    int priority = manufOrderList.stream().mapToInt(ManufOrder::getPrioritySelect).max().orElse(2);
    Unit unit = billOfMaterial.getUnit();
    BigDecimal qty = BigDecimal.ZERO;
    String note = "";
    ManufOrder mergedManufOrder = new ManufOrder();
    for (ManufOrder manufOrder : manufOrderList) {
        manufOrder.setStatusSelect(ManufOrderRepository.STATUS_MERGED);
        manufOrder.setManufOrderMergeResult(mergedManufOrder);
        for (ProductionOrder productionOrder : manufOrder.getProductionOrderSet()) {
            mergedManufOrder.addProductionOrderSetItem(productionOrder);
        }
        for (SaleOrder saleOrder : manufOrder.getSaleOrderSet()) {
            mergedManufOrder.addSaleOrderSetItem(saleOrder);
        }
        /*
       * If unit are the same, then add the qty If not, convert the unit and get the converted qty
       */
        if (manufOrder.getUnit().equals(unit)) {
            qty = qty.add(manufOrder.getQty());
        } else {
            BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(manufOrder.getUnit(), unit, manufOrder.getQty(), appBaseService.getNbDecimalDigitForQty(), null);
            qty = qty.add(qtyConverted);
        }
        if (manufOrder.getNote() != null && !manufOrder.getNote().equals("")) {
            note += manufOrder.getManufOrderSeq() + " : " + manufOrder.getNote() + "\n";
        }
    }
    Optional<LocalDateTime> minDate = manufOrderList.stream().filter(mo -> mo.getPlannedStartDateT() != null).map(ManufOrder::getPlannedStartDateT).min(LocalDateTime::compareTo);
    minDate.ifPresent(mergedManufOrder::setPlannedStartDateT);
    /* Update the created manuf order */
    mergedManufOrder.setStatusSelect(ManufOrderRepository.STATUS_DRAFT);
    mergedManufOrder.setProduct(product);
    mergedManufOrder.setUnit(unit);
    mergedManufOrder.setWorkshopStockLocation(stockLocation);
    mergedManufOrder.setQty(qty);
    mergedManufOrder.setBillOfMaterial(billOfMaterial);
    mergedManufOrder.setCompany(company);
    mergedManufOrder.setPrioritySelect(priority);
    mergedManufOrder.setProdProcess(billOfMaterial.getProdProcess());
    mergedManufOrder.setNote(note);
    /*
     * Check the config to see if you directly plan the created manuf order or just prefill the
     * operations
     */
    if (appProductionService.isApp("production") && appProductionService.getAppProduction().getIsManufOrderPlannedAfterMerge()) {
        manufOrderWorkflowService.plan(mergedManufOrder);
    } else {
        preFillOperations(mergedManufOrder);
    }
    manufOrderRepo.save(mergedManufOrder);
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductVariantService(com.axelor.apps.base.service.ProductVariantService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Joiner(com.google.common.base.Joiner) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LocalDateTime(java.time.LocalDateTime) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) StringTool(com.axelor.apps.tool.StringTool) Sequence(com.axelor.apps.base.db.Sequence) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MoreObjects(com.google.common.base.MoreObjects) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) Comparator(java.util.Comparator) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Collections(java.util.Collections) LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) Unit(com.axelor.apps.base.db.Unit) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) Transactional(com.google.inject.persist.Transactional)

Example 40 with StockLocation

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

the class ManufOrderServiceImpl method generateWasteStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
    StockMove wasteStockMove = null;
    Company company = manufOrder.getCompany();
    if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
        return wasteStockMove;
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
    StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
    wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
    for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
        stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
    }
    stockMoveService.validate(wasteStockMove);
    manufOrder.setWasteStockMove(wasteStockMove);
    return wasteStockMove;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5