Search in sources :

Example 6 with StockConfig

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

the class LogisticalFormServiceImpl method processCollected.

@Override
@Transactional(rollbackOn = { Exception.class })
public void processCollected(LogisticalForm logisticalForm) throws AxelorException {
    if (logisticalForm.getLogisticalFormLineList() == null) {
        return;
    }
    Set<StockMove> stockMoveSet = new HashSet<>();
    logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    stockMoveSet.forEach(stockMoveService::updateFullySpreadOverLogisticalFormsFlag);
    StockConfigService stockConfigService = Beans.get(StockConfigService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(logisticalForm.getCompany());
    if (stockConfig.getRealizeStockMovesUponParcelPalletCollection()) {
        for (StockMove stockMove : stockMoveSet) {
            if (stockMove.getFullySpreadOverLogisticalFormsFlag()) {
                stockMoveService.realize(stockMove);
            }
        }
    }
    logisticalForm.setStatusSelect(LogisticalFormRepository.STATUS_COLLECTED);
}
Also used : Inject(com.google.inject.Inject) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) Mapper(com.axelor.db.mapper.Mapper) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) Locale(java.util.Locale) Map(java.util.Map) FreightCarrierCustomerAccountNumber(com.axelor.apps.stock.db.FreightCarrierCustomerAccountNumber) RoundingMode(java.math.RoundingMode) LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LogisticalFormLineRepository(com.axelor.apps.stock.db.repo.LogisticalFormLineRepository) List(java.util.List) Product(com.axelor.apps.base.db.Product) ScriptHelper(com.axelor.script.ScriptHelper) Entry(java.util.Map.Entry) Optional(java.util.Optional) AppFilter(com.axelor.app.internal.AppFilter) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) TypedQuery(javax.persistence.TypedQuery) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) ContextEntity(com.axelor.rpc.ContextEntity) I18n(com.axelor.i18n.I18n) LogisticalFormRepository(com.axelor.apps.stock.db.repo.LogisticalFormRepository) LinkedHashSet(java.util.LinkedHashSet) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LogisticalFormWarning(com.axelor.apps.stock.exception.LogisticalFormWarning) QueryBuilder(com.axelor.apps.tool.QueryBuilder) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockConfig(com.axelor.apps.stock.db.StockConfig) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Transactional(com.google.inject.persist.Transactional)

Example 7 with StockConfig

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

the class PartnerStockSettingsServiceImpl method createMailSettings.

@Override
@Transactional(rollbackOn = { Exception.class })
public PartnerStockSettings createMailSettings(Partner partner, Company company) throws AxelorException {
    PartnerStockSettings mailSettings = new PartnerStockSettings();
    mailSettings.setCompany(company);
    StockConfig stockConfig = Beans.get(StockConfigService.class).getStockConfig(company);
    mailSettings.setPlannedStockMoveAutomaticMail(stockConfig.getPlannedStockMoveAutomaticMail());
    mailSettings.setPlannedStockMoveMessageTemplate(stockConfig.getPlannedStockMoveMessageTemplate());
    mailSettings.setRealStockMoveAutomaticMail(stockConfig.getRealStockMoveAutomaticMail());
    mailSettings.setRealStockMoveMessageTemplate(stockConfig.getRealStockMoveMessageTemplate());
    partner.addPartnerStockSettingsListItem(mailSettings);
    return Beans.get(PartnerStockSettingsRepository.class).save(mailSettings);
}
Also used : PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) StockConfig(com.axelor.apps.stock.db.StockConfig) PartnerStockSettingsRepository(com.axelor.apps.stock.db.repo.PartnerStockSettingsRepository) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) Transactional(com.google.inject.persist.Transactional)

Example 8 with StockConfig

use of com.axelor.apps.stock.db.StockConfig 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)

Example 9 with StockConfig

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

the class ManufOrderStockMoveService method partialFinish.

/**
 * Allows to create and realize in or out stock moves for the given manufacturing order.
 *
 * @param manufOrder
 * @param inOrOut can be {@link ManufOrderStockMoveService#PART_FINISH_IN} or {@link
 *     ManufOrderStockMoveService#PART_FINISH_OUT}
 * @throws AxelorException
 */
protected void partialFinish(ManufOrder manufOrder, int inOrOut) throws AxelorException {
    if (inOrOut != PART_FINISH_IN && inOrOut != PART_FINISH_OUT) {
        throw new IllegalArgumentException(I18n.get(IExceptionMessage.IN_OR_OUT_INVALID_ARG));
    }
    Company company = manufOrder.getCompany();
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation fromStockLocation;
    StockLocation toStockLocation;
    List<StockMove> stockMoveList;
    if (inOrOut == PART_FINISH_IN) {
        stockMoveList = manufOrder.getInStockMoveList();
        fromStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
        toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
    } else {
        stockMoveList = manufOrder.getOutStockMoveList();
        fromStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
        toStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_OUT);
    }
    // realize current stock move and update the price
    Optional<StockMove> stockMoveToRealize = getPlannedStockMove(stockMoveList);
    if (stockMoveToRealize.isPresent()) {
        updateRealPrice(manufOrder, stockMoveToRealize.get());
        finishStockMove(stockMoveToRealize.get());
    }
    // generate new stock move
    StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
    newStockMove.setStockMoveLineList(new ArrayList<>());
    newStockMove.setOrigin(manufOrder.getManufOrderSeq());
    newStockMove.setOriginId(manufOrder.getId());
    newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
    createNewStockMoveLines(manufOrder, newStockMove, inOrOut);
    if (!newStockMove.getStockMoveLineList().isEmpty()) {
        // plan the stockmove
        stockMoveService.plan(newStockMove);
        if (inOrOut == PART_FINISH_IN) {
            manufOrder.addInStockMoveListItem(newStockMove);
            newStockMove.getStockMoveLineList().forEach(manufOrder::addConsumedStockMoveLineListItem);
            manufOrder.clearDiffConsumeProdProductList();
        } else {
            manufOrder.addOutStockMoveListItem(newStockMove);
            newStockMove.getStockMoveLineList().forEach(manufOrder::addProducedStockMoveLineListItem);
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService)

Example 10 with StockConfig

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

the class ManufOrderStockMoveService method getDefaultStockLocation.

/**
 * Given a manuf order, its company and whether we want to create a in or out stock move,
 * determine the default stock location and return it. First search in prodprocess, then in
 * company stock configuration.
 *
 * @param manufOrder a manufacturing order.
 * @param company a company with stock config.
 * @param inOrOut can be {@link ManufOrderStockMoveService#STOCK_LOCATION_IN} or {@link
 *     ManufOrderStockMoveService#STOCK_LOCATION_OUT}.
 * @return the found stock location, which can be null.
 * @throws AxelorException if the stock config is missing for the company.
 */
public StockLocation getDefaultStockLocation(ManufOrder manufOrder, Company company, int inOrOut) throws AxelorException {
    if (inOrOut != STOCK_LOCATION_IN && inOrOut != STOCK_LOCATION_OUT) {
        throw new IllegalArgumentException(I18n.get(IExceptionMessage.IN_OR_OUT_INVALID_ARG));
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation stockLocation = getDefaultStockLocation(manufOrder.getProdProcess(), inOrOut);
    if (stockLocation == null) {
        stockLocation = inOrOut == STOCK_LOCATION_IN ? stockConfigService.getComponentDefaultStockLocation(stockConfig) : stockConfigService.getFinishedProductsDefaultStockLocation(stockConfig);
    }
    return stockLocation;
}
Also used : StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService)

Aggregations

StockConfig (com.axelor.apps.stock.db.StockConfig)16 StockLocation (com.axelor.apps.stock.db.StockLocation)8 Company (com.axelor.apps.base.db.Company)7 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)7 AxelorException (com.axelor.exception.AxelorException)7 StockMove (com.axelor.apps.stock.db.StockMove)6 StockConfigService (com.axelor.apps.stock.service.config.StockConfigService)6 Transactional (com.google.inject.persist.Transactional)5 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Product (com.axelor.apps.base.db.Product)2 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 ProdProduct (com.axelor.apps.production.db.ProdProduct)2 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)2 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)2 StockMoveService (com.axelor.apps.stock.service.StockMoveService)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2 List (java.util.List)2