use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method pause.
@Transactional
public void pause(ManufOrder manufOrder) {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_IN_PROGRESS) {
operationOrderWorkflowService.pause(operationOrder);
}
}
}
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_STANDBY);
manufOrderRepo.save(manufOrder);
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method cancel.
@Transactional(rollbackOn = { Exception.class })
public void cancel(ManufOrder manufOrder, CancelReason cancelReason, String cancelReasonStr) throws AxelorException {
if (cancelReason == null && manufOrder.getStatusSelect() != ManufOrderRepository.STATUS_DRAFT && manufOrder.getStatusSelect() != ManufOrderRepository.STATUS_PLANNED) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MANUF_ORDER_CANCEL_REASON_ERROR));
}
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_CANCELED) {
operationOrderWorkflowService.cancel(operationOrder);
}
}
}
manufOrderStockMoveService.cancel(manufOrder);
if (manufOrder.getConsumedStockMoveLineList() != null) {
manufOrder.getConsumedStockMoveLineList().forEach(stockMoveLine -> stockMoveLine.setConsumedManufOrder(null));
}
if (manufOrder.getProducedStockMoveLineList() != null) {
manufOrder.getProducedStockMoveLineList().forEach(stockMoveLine -> stockMoveLine.setProducedManufOrder(null));
}
if (manufOrder.getDiffConsumeProdProductList() != null) {
manufOrder.clearDiffConsumeProdProductList();
}
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_CANCELED);
if (cancelReason != null) {
manufOrder.setCancelReason(cancelReason);
if (Strings.isNullOrEmpty(cancelReasonStr)) {
manufOrder.setCancelReasonStr(cancelReason.getName());
} else {
manufOrder.setCancelReasonStr(cancelReasonStr);
}
}
manufOrderRepo.save(manufOrder);
Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method updatePlannedDates.
/**
* Update planned dates.
*
* @param manufOrder
* @param plannedStartDateT
*/
@Transactional(rollbackOn = { Exception.class })
public void updatePlannedDates(ManufOrder manufOrder, LocalDateTime plannedStartDateT) throws AxelorException {
manufOrder.setPlannedStartDateT(plannedStartDateT);
if (manufOrder.getOperationOrderList() != null) {
List<OperationOrder> operationOrderList = getSortedOperationOrderList(manufOrder);
operationOrderWorkflowService.resetPlannedDates(operationOrderList);
for (OperationOrder operationOrder : operationOrderList) {
operationOrderWorkflowService.replan(operationOrder);
}
}
manufOrder.setPlannedEndDateT(computePlannedEndDateT(manufOrder));
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method plan.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public List<ManufOrder> plan(List<ManufOrder> manufOrderList, boolean quickSolve) throws AxelorException {
ManufOrderService manufOrderService = Beans.get(ManufOrderService.class);
SequenceService sequenceService = Beans.get(SequenceService.class);
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getBillOfMaterial().getStatusSelect() != BillOfMaterialRepository.STATUS_APPLICABLE || manufOrder.getProdProcess().getStatusSelect() != ProdProcessRepository.STATUS_APPLICABLE) {
throw new AxelorException(manufOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CHECK_BOM_AND_PROD_PROCESS));
}
if (sequenceService.isEmptyOrDraftSequenceNumber(manufOrder.getManufOrderSeq())) {
manufOrder.setManufOrderSeq(manufOrderService.getManufOrderSeq(manufOrder));
}
if (CollectionUtils.isEmpty(manufOrder.getOperationOrderList())) {
manufOrderService.preFillOperations(manufOrder);
} else {
manufOrderService.updateOperationsName(manufOrder);
}
if (!manufOrder.getIsConsProOnOperation() && CollectionUtils.isEmpty(manufOrder.getToConsumeProdProductList())) {
manufOrderService.createToConsumeProdProductList(manufOrder);
}
if (CollectionUtils.isEmpty(manufOrder.getToProduceProdProductList())) {
manufOrderService.createToProduceProdProductList(manufOrder);
}
if (manufOrder.getPlannedStartDateT() == null && manufOrder.getPlannedEndDateT() == null) {
manufOrder.setPlannedStartDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
} else if (manufOrder.getPlannedStartDateT() == null && manufOrder.getPlannedEndDateT() != null) {
long duration = 0;
for (OperationOrder order : manufOrder.getOperationOrderList()) {
duration += operationOrderWorkflowService.computeEntireCycleDuration(order, // in seconds
order.getManufOrder().getQty());
}
manufOrder.setPlannedStartDateT(manufOrder.getPlannedEndDateT().minusSeconds(duration));
}
}
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : getSortedOperationOrderList(manufOrder)) {
operationOrderWorkflowService.plan(operationOrder, null);
}
}
}
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getPlannedEndDateT() == null) {
manufOrder.setPlannedEndDateT(this.computePlannedEndDateT(manufOrder));
}
if (manufOrder.getBillOfMaterial() != null) {
manufOrder.setUnit(manufOrder.getBillOfMaterial().getUnit());
}
if (!manufOrder.getIsConsProOnOperation()) {
manufOrderStockMoveService.createToConsumeStockMove(manufOrder);
}
manufOrderStockMoveService.createToProduceStockMove(manufOrder);
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_PLANNED);
manufOrder.setCancelReason(null);
manufOrder.setCancelReasonStr(null);
manufOrderRepo.save(manufOrder);
Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
}
return manufOrderList;
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method finish.
@Transactional(rollbackOn = { Exception.class })
public boolean finish(ManufOrder manufOrder) throws AxelorException {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_FINISHED) {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_IN_PROGRESS && operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_STANDBY) {
operationOrderWorkflowService.start(operationOrder);
}
operationOrderWorkflowService.finish(operationOrder);
}
}
}
// create cost sheet
Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_END_OF_PRODUCTION, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
// update price in product
Product product = manufOrder.getProduct();
Company company = manufOrder.getCompany();
if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_FORECAST) {
productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
} else if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_REAL) {
BigDecimal costPrice = computeOneUnitProductionPrice(manufOrder);
if (costPrice.signum() != 0) {
productCompanyService.set(product, "lastProductionPrice", costPrice, company);
}
} else {
// default value is forecast
productCompanyService.set(product, "realOrEstimatedPriceSelect", ProductRepository.PRICE_METHOD_FORECAST, company);
productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
}
// update costprice in product
if (((Integer) productCompanyService.get(product, "costTypeSelect", company)) == ProductRepository.COST_TYPE_LAST_PRODUCTION_PRICE) {
productCompanyService.set(product, "costPrice", (BigDecimal) productCompanyService.get(product, "lastProductionPrice", company), company);
if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", company)) {
Beans.get(ProductService.class).updateSalePrice(product, company);
}
}
manufOrderStockMoveService.finish(manufOrder);
manufOrder.setRealEndDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_FINISHED);
manufOrder.setEndTimeDifference(new BigDecimal(ChronoUnit.MINUTES.between(manufOrder.getPlannedEndDateT(), manufOrder.getRealEndDateT())));
manufOrderRepo.save(manufOrder);
Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
ProductionConfig productionConfig = manufOrder.getCompany() != null ? productionConfigRepo.findByCompany(manufOrder.getCompany()) : null;
if (productionConfig != null && productionConfig.getFinishMoAutomaticEmail()) {
return this.sendMail(manufOrder, productionConfig.getFinishMoMessageTemplate());
}
return true;
}
Aggregations