use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method _createToConsumeStockMove.
public StockMove _createToConsumeStockMove(ManufOrder manufOrder, Company company) throws AxelorException {
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation virtualStockLocation = manufOrder.getOutsourcing() ? manufOrder.getProdProcess().getProducedProductStockLocation() : stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
StockLocation fromStockLocation = manufOrder.getOutsourcing() ? company.getStockConfig().getOutsourcingReceiptStockLocation() : getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
StockMove stockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, virtualStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
stockMove.setOriginId(manufOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
stockMove.setOrigin(manufOrder.getManufOrderSeq());
return stockMove;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class OperationOrderStockMoveService method partialFinish.
/**
* Allows to create and realize in stock moves for the given operation order. This method is used
* during a partial finish.
*
* @param operationOrder
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void partialFinish(OperationOrder operationOrder) throws AxelorException {
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
ManufOrder manufOrder = operationOrder.getManufOrder();
Company company = manufOrder.getCompany();
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation fromStockLocation;
StockLocation toStockLocation;
List<StockMove> stockMoveList;
stockMoveList = operationOrder.getInStockMoveList();
fromStockLocation = manufOrderStockMoveService.getDefaultStockLocation(manufOrder, company, ManufOrderStockMoveService.STOCK_LOCATION_IN);
toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
// realize current stock move
Optional<StockMove> stockMoveToRealize = stockMoveList.stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED && !CollectionUtils.isEmpty(stockMove.getStockMoveLineList())).findFirst();
if (stockMoveToRealize.isPresent()) {
manufOrderStockMoveService.finishStockMove(stockMoveToRealize.get());
}
// generate new stock move
StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
newStockMove.setOrigin(operationOrder.getOperationName());
newStockMove.setOriginId(operationOrder.getId());
newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
newStockMove.setStockMoveLineList(new ArrayList<>());
createNewStockMoveLines(operationOrder, newStockMove);
if (!newStockMove.getStockMoveLineList().isEmpty()) {
// plan the stockmove
stockMoveService.plan(newStockMove);
operationOrder.addInStockMoveListItem(newStockMove);
newStockMove.getStockMoveLineList().forEach(operationOrder::addConsumedStockMoveLineListItem);
operationOrder.clearDiffConsumeProdProductList();
}
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ConfiguratorProdProcessServiceImpl method generateProdProcessService.
@Override
public ProdProcess generateProdProcessService(ConfiguratorProdProcess confProdProcess, JsonContext attributes, Product product) throws AxelorException {
if (confProdProcess == null) {
return null;
}
String code;
StockLocation stockLocation;
StockLocation producedProductStockLocation;
StockLocation workshopStockLocation;
if (confProdProcess.getDefCodeAsFormula()) {
code = String.valueOf(configuratorService.computeFormula(confProdProcess.getCodeFormula(), attributes));
} else {
code = confProdProcess.getCode();
}
if (confProdProcess.getDefStockLocationAsFormula()) {
stockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getStockLocationFormula(), attributes);
} else {
stockLocation = confProdProcess.getStockLocation();
}
if (confProdProcess.getDefProducedProductStockLocationAsFormula()) {
producedProductStockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getProducedProductStockLocationFormula(), attributes);
} else {
producedProductStockLocation = confProdProcess.getProducedProductStockLocation();
}
if (confProdProcess.getDefWorkshopStockLocationAsFormula()) {
workshopStockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getWorkshopStockLocationFormula(), attributes);
} else {
workshopStockLocation = confProdProcess.getWorkshopStockLocation();
}
ProdProcess prodProcess = createProdProcessHeader(confProdProcess, code, stockLocation, producedProductStockLocation, workshopStockLocation, product);
List<ConfiguratorProdProcessLine> confLines = confProdProcess.getConfiguratorProdProcessLineList();
if (confLines != null) {
for (ConfiguratorProdProcessLine confLine : confLines) {
prodProcess.addProdProcessLineListItem(confProdProcessLineService.generateProdProcessLine(confLine, attributes));
}
}
return prodProcess;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method createManufOrderMrpLines.
@Transactional(rollbackOn = { Exception.class })
protected void createManufOrderMrpLines(Mrp mrp, ManufOrder manufOrder, MrpLineType manufOrderMrpLineType, MrpLineType manufOrderNeedMrpLineType) throws AxelorException {
StockLocation stockLocation = manufOrder.getProdProcess().getStockLocation();
LocalDate maturityDate = null;
if (manufOrder.getPlannedEndDateT() != null) {
maturityDate = manufOrder.getPlannedEndDateT().toLocalDate();
} else {
maturityDate = manufOrder.getPlannedStartDateT().toLocalDate();
}
maturityDate = this.computeMaturityDate(maturityDate, manufOrderMrpLineType);
for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
Product product = prodProduct.getProduct();
if ((this.isBeforeEndDate(maturityDate) || manufOrderMrpLineType.getIgnoreEndDate()) && this.isMrpProduct(product)) {
MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderMrpLineType, prodProduct.getQty(), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
if (manufOrderNeedMrpLineType == null) {
return;
}
if (manufOrder.getIsConsProOnOperation()) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
Product product = prodProduct.getProduct();
if (this.isMrpProduct(product)) {
maturityDate = null;
if (operationOrder.getPlannedEndDateT() != null) {
maturityDate = operationOrder.getPlannedEndDateT().toLocalDate();
} else {
maturityDate = operationOrder.getPlannedStartDateT().toLocalDate();
}
maturityDate = this.computeMaturityDate(maturityDate, manufOrderNeedMrpLineType);
MrpLine mrpLine = this.createMrpLine(mrp, prodProduct.getProduct(), manufOrderNeedMrpLineType, computeQtyLeftToConsume(operationOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, operationOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
}
} else {
for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
Product product = prodProduct.getProduct();
if (this.isMrpProduct(product)) {
// add it with the level of manuf order product + 1.
if (!this.productMap.containsKey(product.getId())) {
this.assignProductAndLevel(product, manufOrder.getProduct());
this.createAvailableStockMrpLine(product, manufOrder.getProdProcess().getStockLocation());
}
MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderNeedMrpLineType, computeQtyLeftToConsume(manufOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
if (mrpLine != null) {
mrpLineRepository.save(mrpLine);
}
}
}
}
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class StockRulesServiceProductionImpl method generateOrder.
public void generateOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
StockLocation stockLocation = stockLocationLine.getStockLocation();
if (stockLocation == null) {
return;
}
StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
if (stockRules == null) {
return;
}
if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_PRODUCTION_ORDER)) {
this.generateProductionOrder(product, qty, stockLocationLine, type, stockRules);
} else {
this.generatePurchaseOrder(product, qty, stockLocationLine, type);
}
}
Aggregations