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