Search in sources :

Example 1 with UnitCostCalculation

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

the class UnitCostCalculationController method runUnitCostCalc.

public void runUnitCostCalc(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
        unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
        Beans.get(UnitCostCalculationService.class).runUnitCostCalc(unitCostCalculation);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException)

Example 2 with UnitCostCalculation

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

the class UnitCostCalculationController method exportUnitCostCalc.

public void exportUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
    try {
        UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
        unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
        String fileName = unitCostCalculation.getUnitCostCalcSeq() + "-" + Beans.get(AppProductionService.class).getTodayDateTime().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
        MetaFile metaFile = Beans.get(UnitCostCalculationService.class).exportUnitCostCalc(unitCostCalculation, fileName);
        response.setView(ActionView.define(fileName).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + metaFile.getId() + "/content/download?v=" + metaFile.getVersion()).map());
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException) AppProductionService(com.axelor.apps.production.service.app.AppProductionService)

Example 3 with UnitCostCalculation

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

the class UnitCostCalculationController method updateUnitCosts.

public void updateUnitCosts(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
        unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
        Beans.get(UnitCostCalculationService.class).updateUnitCosts(unitCostCalculation);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException)

Example 4 with UnitCostCalculation

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

the class UnitCostCalculationController method importUnitCostCalc.

@SuppressWarnings("unchecked")
public void importUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
    try {
        LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) request.getContext().get("metaFile");
        MetaFile dataFile = Beans.get(MetaFileRepository.class).find(((Integer) map.get("id")).longValue());
        File csvFile = MetaFiles.getPath(dataFile).toFile();
        Long unitCostCalculationId = Long.valueOf(request.getContext().get("_id").toString());
        UnitCostCalculation unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculationId);
        if (Files.getFileExtension(csvFile.getName()).equals("csv")) {
            Beans.get(UnitCostCalculationService.class).importUnitCostCalc(dataFile, unitCostCalculation);
            response.setCanClose(true);
        } else {
            response.setError(IExceptionMessage.UNIT_COST_CALCULATION_IMPORT_CSV_ERROR);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) MetaFile(com.axelor.meta.db.MetaFile) UnitCostCalculationRepository(com.axelor.apps.production.db.repo.UnitCostCalculationRepository) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

UnitCostCalculation (com.axelor.apps.production.db.UnitCostCalculation)4 UnitCostCalculationService (com.axelor.apps.production.service.costsheet.UnitCostCalculationService)4 AxelorException (com.axelor.exception.AxelorException)4 IOException (java.io.IOException)4 MetaFile (com.axelor.meta.db.MetaFile)2 UnitCostCalculationRepository (com.axelor.apps.production.db.repo.UnitCostCalculationRepository)1 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)1 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)1 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1