Search in sources :

Example 1 with StockMove

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

the class LogisticalFormServiceImpl method getSpreadableQtyMap.

@Override
public Map<StockMoveLine, BigDecimal> getSpreadableQtyMap(LogisticalForm logisticalForm) {
    Set<StockMove> stockMoveSet = new LinkedHashSet<>();
    Map<StockMoveLine, BigDecimal> spreadableQtyMap = new LinkedHashMap<>();
    if (logisticalForm.getLogisticalFormLineList() != null) {
        StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
        logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
        for (StockMove stockMove : stockMoveSet) {
            if (stockMove.getStockMoveLineList() == null) {
                continue;
            }
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
                spreadableQtyMap.put(stockMoveLine, spreadableQty);
            }
        }
    }
    return spreadableQtyMap;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with StockMove

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

the class StockCorrectionServiceImpl method generateStockMove.

public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
    StockLocation toStockLocation = stockCorrection.getStockLocation();
    Company company = toStockLocation.getCompany();
    StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    StockLocationLine stockLocationLine = null;
    StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
    if (stockCorrection.getTrackingNumber() == null) {
        stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
    } else {
        stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
    }
    BigDecimal realQty = stockCorrection.getRealQty();
    Product product = stockCorrection.getProduct();
    TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
    BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
    StockMove stockMove = null;
    if (diff.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    } else if (diff.compareTo(BigDecimal.ZERO) > 0) {
        stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
    } else {
        stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
    }
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
    stockMove.setOriginId(stockCorrection.getId());
    stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
    BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
    StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
    if (stockMoveLine == null) {
        throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
    }
    if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
        stockMoveLine.setTrackingNumber(trackingNumber);
    }
    stockMoveService.plan(stockMove);
    stockMoveService.copyQtyToRealQty(stockMove);
    stockMoveService.realize(stockMove, false);
    return stockMove;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 3 with StockMove

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

the class StockCorrectionServiceImpl method validate.

@Override
@Transactional(rollbackOn = { Exception.class })
public boolean validate(StockCorrection stockCorrection) throws AxelorException {
    AppBaseService baseService = Beans.get(AppBaseService.class);
    StockMove stockMove = generateStockMove(stockCorrection);
    if (stockMove != null) {
        stockCorrection.setStatusSelect(StockCorrectionRepository.STATUS_VALIDATED);
        stockCorrection.setValidationDateT(baseService.getTodayDateTime().toLocalDateTime());
        return true;
    }
    return false;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Transactional(com.google.inject.persist.Transactional)

Example 4 with StockMove

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

the class InventoryService method cancel.

@Transactional(rollbackOn = { Exception.class })
public void cancel(Inventory inventory) throws AxelorException {
    List<StockMove> stockMoveList = stockMoveRepo.all().filter("self.originTypeSelect = :originTypeSelect AND self.originId = :originId").bind("originTypeSelect", StockMoveRepository.ORIGIN_INVENTORY).bind("originId", inventory.getId()).fetch();
    for (StockMove stockMove : stockMoveList) {
        stockMoveService.cancel(stockMove);
    }
    inventory.setStatusSelect(InventoryRepository.STATUS_CANCELED);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Transactional(com.google.inject.persist.Transactional)

Example 5 with StockMove

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

the class LogisticalFormServiceImpl method getFullySpreadStockMoveList.

protected List<StockMove> getFullySpreadStockMoveList(LogisticalForm logisticalForm) {
    List<StockMove> fullySpreadStockMoveList = new ArrayList<>();
    List<StockMoveLine> fullySpreadStockMoveLineList = getFullySpreadStockMoveLineList(logisticalForm);
    Set<StockMove> stockMoveSet = new HashSet<>();
    for (StockMoveLine stockMoveLine : fullySpreadStockMoveLineList) {
        stockMoveSet.add(stockMoveLine.getStockMove());
    }
    for (StockMove stockMove : stockMoveSet) {
        if (fullySpreadStockMoveLineList.containsAll(stockMove.getStockMoveLineList())) {
            fullySpreadStockMoveList.add(stockMove);
        }
    }
    return fullySpreadStockMoveList;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)129 AxelorException (com.axelor.exception.AxelorException)57 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)50 ArrayList (java.util.ArrayList)36 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)33 Transactional (com.google.inject.persist.Transactional)32 StockMoveService (com.axelor.apps.stock.service.StockMoveService)31 BigDecimal (java.math.BigDecimal)30 List (java.util.List)25 Company (com.axelor.apps.base.db.Company)23 Map (java.util.Map)21 Product (com.axelor.apps.base.db.Product)19 Invoice (com.axelor.apps.account.db.Invoice)18 StockLocation (com.axelor.apps.stock.db.StockLocation)18 Beans (com.axelor.inject.Beans)17 Optional (java.util.Optional)16 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)15 I18n (com.axelor.i18n.I18n)15 Inject (com.google.inject.Inject)14 HashMap (java.util.HashMap)14