use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method resume.
@Transactional
public void resume(ManufOrder manufOrder) {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_STANDBY) {
operationOrderWorkflowService.resume(operationOrder);
}
}
}
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_IN_PROGRESS);
manufOrderRepo.save(manufOrder);
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method allOpFinished.
@Transactional(rollbackOn = { Exception.class })
public void allOpFinished(ManufOrder manufOrder) throws AxelorException {
int count = 0;
List<OperationOrder> operationOrderList = manufOrder.getOperationOrderList();
for (OperationOrder operationOrderIt : operationOrderList) {
if (operationOrderIt.getStatusSelect() == OperationOrderRepository.STATUS_FINISHED) {
count++;
}
}
if (count == operationOrderList.size()) {
this.finish(manufOrder);
}
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class OperationOrderServiceImpl method updateConsumedStockMoveFromOperationOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromOperationOrder(OperationOrder operationOrder) throws AxelorException {
this.updateDiffProdProductList(operationOrder);
List<StockMoveLine> consumedStockMoveLineList = operationOrder.getConsumedStockMoveLineList();
if (consumedStockMoveLineList == null) {
return;
}
Optional<StockMove> stockMoveOpt = operationOrder.getInStockMoveList().stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED).findFirst();
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = Beans.get(ManufOrderStockMoveService.class)._createToConsumeStockMove(operationOrder.getManufOrder(), operationOrder.getManufOrder().getCompany());
operationOrder.addInStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
Beans.get(ManufOrderService.class).updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class OperationOrderServiceImpl method chargeByMachineHours.
public List<Map<String, Object>> chargeByMachineHours(LocalDateTime fromDateTime, LocalDateTime toDateTime) throws AxelorException {
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
LocalDateTime itDateTime = LocalDateTime.parse(fromDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
OperationOrderRepository operationOrderRepo = Beans.get(OperationOrderRepository.class);
if (Duration.between(fromDateTime, toDateTime).toDays() > 20) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS));
}
List<OperationOrder> operationOrderListTemp = operationOrderRepo.all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime).fetch();
Set<String> machineNameList = new HashSet<String>();
for (OperationOrder operationOrder : operationOrderListTemp) {
if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
}
}
}
while (!itDateTime.isAfter(toDateTime)) {
List<OperationOrder> operationOrderList = operationOrderRepo.all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)).fetch();
Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
for (OperationOrder operationOrder : operationOrderList) {
if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
String machine = operationOrder.getWorkCenter().getMachine().getName();
long numberOfMinutes = 0;
if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
numberOfMinutes = Duration.between(itDateTime, operationOrder.getPlannedEndDateT()).toMinutes();
} else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)).toMinutes();
} else {
numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).toMinutes();
}
if (numberOfMinutes > 60) {
numberOfMinutes = 60;
}
BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
if (map.containsKey(machine)) {
map.put(machine, map.get(machine).add(percentage));
} else {
map.put(machine, percentage);
}
}
}
Set<String> keyList = map.keySet();
for (String key : machineNameList) {
if (keyList.contains(key)) {
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
dataMap.put("charge", (Object) map.get(key));
dataMap.put("machine", (Object) key);
dataList.add(dataMap);
} else {
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
dataMap.put("charge", (Object) BigDecimal.ZERO);
dataMap.put("machine", (Object) key);
dataList.add(dataMap);
}
}
itDateTime = itDateTime.plusHours(1);
}
return dataList;
}
use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.
the class OperationOrderServiceImpl method createOperationOrder.
@Transactional(rollbackOn = { Exception.class })
public OperationOrder createOperationOrder(ManufOrder manufOrder, int priority, WorkCenter workCenter, Machine machine, MachineTool machineTool, ProdProcessLine prodProcessLine) throws AxelorException {
logger.debug("Création d'une opération {} pour l'OF {}", priority, manufOrder.getManufOrderSeq());
String operationName = prodProcessLine.getName();
OperationOrder operationOrder = new OperationOrder(priority, this.computeName(manufOrder, priority, operationName), operationName, manufOrder, workCenter, machine, OperationOrderRepository.STATUS_DRAFT, prodProcessLine, machineTool);
this._createHumanResourceList(operationOrder, workCenter);
operationOrder.setUseLineInGeneratedPurchaseOrder(prodProcessLine.getUseLineInGeneratedPurchaseOrder());
return Beans.get(OperationOrderRepository.class).save(operationOrder);
}
Aggregations