Search in sources :

Example 6 with WorkCenter

use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.

the class ProdProcessLineController method updateCapacitySettings.

public void updateCapacitySettings(ActionRequest request, ActionResponse response) {
    try {
        ProdProcessLine prodProcess = request.getContext().asType(ProdProcessLine.class);
        WorkCenter workCenter = prodProcess.getWorkCenter();
        if (workCenter != null) {
            response.setValue("minCapacityPerCycle", Beans.get(ProdProcessLineService.class).getProdProcessLineMinCapacityPerCycleFromWorkCenter(workCenter));
            response.setValue("maxCapacityPerCycle", Beans.get(ProdProcessLineService.class).getProdProcessLineMaxCapacityPerCycleFromWorkCenter(workCenter));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : WorkCenter(com.axelor.apps.production.db.WorkCenter) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine)

Example 7 with WorkCenter

use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.

the class OperationOrderWorkflowService method computeEntireCycleDuration.

public long computeEntireCycleDuration(OperationOrder operationOrder, BigDecimal qty) throws AxelorException {
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    WorkCenter workCenter = prodProcessLine.getWorkCenter();
    long duration = 0;
    if (prodProcessLine.getWorkCenter() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PROD_PROCESS_LINE_MISSING_WORK_CENTER), prodProcessLine.getProdProcess() != null ? prodProcessLine.getProdProcess().getCode() : "null", prodProcessLine.getName());
    }
    BigDecimal maxCapacityPerCycle = prodProcessLine.getMaxCapacityPerCycle();
    BigDecimal nbCycles;
    if (maxCapacityPerCycle.compareTo(BigDecimal.ZERO) == 0) {
        nbCycles = qty;
    } else {
        nbCycles = qty.divide(maxCapacityPerCycle, 0, RoundingMode.UP);
    }
    int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
    if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
        Machine machine = workCenter.getMachine();
        if (machine == null) {
            throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
        }
        duration += machine.getStartingDuration();
        duration += machine.getEndingDuration();
        duration += nbCycles.subtract(new BigDecimal(1)).multiply(new BigDecimal(machine.getSetupDuration())).longValue();
    }
    BigDecimal durationPerCycle = new BigDecimal(prodProcessLine.getDurationPerCycle());
    duration += nbCycles.multiply(durationPerCycle).longValue();
    return duration;
}
Also used : AxelorException(com.axelor.exception.AxelorException) WorkCenter(com.axelor.apps.production.db.WorkCenter) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) BigDecimal(java.math.BigDecimal) Machine(com.axelor.apps.production.db.Machine)

Example 8 with WorkCenter

use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method _computeMachineCost.

protected void _computeMachineCost(ProdProcessLine prodProcessLine, BigDecimal producedQty, Unit pieceUnit, int bomLevel, CostSheetLine parentCostSheetLine) throws AxelorException {
    WorkCenter workCenter = prodProcessLine.getWorkCenter();
    if (prodProcessLine.getWorkCenter() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PROD_PROCESS_LINE_MISSING_WORK_CENTER), prodProcessLine.getProdProcess() != null ? prodProcessLine.getProdProcess().getCode() : "null", prodProcessLine.getName());
    }
    int costType = workCenter.getCostTypeSelect();
    if (costType == WorkCenterRepository.COST_TYPE_PER_CYCLE) {
        costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, this.getNbCycle(producedQty, prodProcessLine.getMaxCapacityPerCycle()), workCenter.getCostAmount(), cycleUnit);
    } else if (costType == WorkCenterRepository.COST_TYPE_PER_HOUR) {
        BigDecimal qty = new BigDecimal(prodProcessLine.getDurationPerCycle()).divide(new BigDecimal(3600), appProductionService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP).multiply(this.getNbCycle(producedQty, prodProcessLine.getMaxCapacityPerCycle()));
        BigDecimal costPrice = workCenter.getCostAmount().multiply(qty);
        costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, qty, costPrice, hourUnit);
    } else if (costType == WorkCenterRepository.COST_TYPE_PER_PIECE) {
        BigDecimal costPrice = workCenter.getCostAmount().multiply(producedQty);
        costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, producedQty, costPrice, pieceUnit);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) WorkCenter(com.axelor.apps.production.db.WorkCenter) BigDecimal(java.math.BigDecimal)

Aggregations

WorkCenter (com.axelor.apps.production.db.WorkCenter)8 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)4 AxelorException (com.axelor.exception.AxelorException)4 Machine (com.axelor.apps.production.db.Machine)2 BigDecimal (java.math.BigDecimal)2 OperationOrder (com.axelor.apps.production.db.OperationOrder)1 WorkCenterGroup (com.axelor.apps.production.db.WorkCenterGroup)1 Transactional (com.google.inject.persist.Transactional)1