Search in sources :

Example 41 with StockMoveLine

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

the class StockMoveLineController method updateQty.

public List<StockMoveLine> updateQty(List<StockMoveLine> moveLines, BigDecimal oldKitQty, BigDecimal newKitQty, boolean isRealQty) {
    BigDecimal qty = BigDecimal.ZERO;
    int scale = appBaseService.getNbDecimalDigitForQty();
    if (moveLines != null) {
        if (newKitQty.compareTo(BigDecimal.ZERO) != 0) {
            for (StockMoveLine line : moveLines) {
                qty = (line.getQty().divide(oldKitQty, scale, RoundingMode.HALF_UP)).multiply(newKitQty);
                line.setQty(qty.setScale(scale, RoundingMode.HALF_UP));
                line.setRealQty(qty.setScale(scale, RoundingMode.HALF_UP));
            }
        } else {
            for (StockMoveLine line : moveLines) {
                line.setQty(qty.setScale(scale, RoundingMode.HALF_UP));
                line.setRealQty(qty.setScale(scale, RoundingMode.HALF_UP));
            }
        }
    }
    return moveLines;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 42 with StockMoveLine

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

the class StockMoveLineController method changeReservedQty.

/**
 * Called from stock move line request quantity wizard view. Call {@link
 * ReservedQtyService#updateReservedQty(StockMoveLine, BigDecimal)}.
 *
 * @param request
 * @param response
 */
public void changeReservedQty(ActionRequest request, ActionResponse response) {
    try {
        StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
        BigDecimal newReservedQty = stockMoveLine.getReservedQty();
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
        Product product = stockMoveLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).updateReservedQty(stockMoveLine, newReservedQty);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 43 with StockMoveLine

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

the class StockMoveLineController method allocateAll.

/**
 * Called from stock move form view, on clicking allocateAll button on one stock move line. Call
 * {@link ReservedQtyService#allocateAll(StockMoveLine)}.
 *
 * @param request
 * @param response
 */
public void allocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
        Product product = stockMoveLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).allocateAll(stockMoveLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 44 with StockMoveLine

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

the class StockMoveLineController method compute.

public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
    StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
    Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
    if (!stockMove.isPresent()) {
        Context parentContext = request.getContext().getParent();
        if (parentContext.getContextClass().equals(StockMove.class)) {
            stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
        } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
            ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
            ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
            stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
        }
        if (!stockMove.isPresent()) {
            return;
        }
    }
    stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
    response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
    response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
    response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 45 with StockMoveLine

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

the class StockMoveLineController method setProductInfo.

/**
 * Called from stock move line form. Fill product info using the company either from the stock
 * move line, from the parent stock move or the parent manuf order.
 *
 * @param request
 * @param response
 */
public void setProductInfo(ActionRequest request, ActionResponse response) {
    StockMoveLine stockMoveLine;
    try {
        stockMoveLine = request.getContext().asType(StockMoveLine.class);
        Company company;
        StockMove stockMove = stockMoveLine.getStockMove();
        if (stockMove == null) {
            Context parentContext = request.getContext().getParent();
            if (parentContext.getContextClass().equals(StockMove.class)) {
                stockMove = parentContext.asType(StockMove.class);
                company = stockMove.getCompany();
            } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
                ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
                company = manufOrder.getCompany();
            } else if (parentContext.getContextClass().equals(OperationOrder.class)) {
                OperationOrder operationOrder = parentContext.asType(OperationOrder.class);
                if (operationOrder.getManufOrder() == null) {
                    return;
                }
                company = operationOrder.getManufOrder().getCompany();
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.STOCK_MOVE_LINE_UNKNOWN_PARENT_CONTEXT);
            }
        } else {
            company = stockMove.getCompany();
        }
        if (stockMoveLine.getProduct() == null) {
            stockMoveLine = new StockMoveLine();
            response.setValues(Mapper.toMap(stockMoveLine));
            return;
        }
        Beans.get(StockMoveLineService.class).setProductInfo(stockMove, stockMoveLine, company);
        response.setValues(stockMoveLine);
    } catch (Exception e) {
        stockMoveLine = new StockMoveLine();
        response.setValues(Mapper.toMap(stockMoveLine));
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) OperationOrder(com.axelor.apps.production.db.OperationOrder) AxelorException(com.axelor.exception.AxelorException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10