Search in sources :

Example 1 with ProductionBatch

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

the class ProductionBatchController method showValuation.

public void showValuation(ActionRequest request, ActionResponse response) throws AxelorException {
    ProductionBatch productionBatch = request.getContext().asType(ProductionBatch.class);
    productionBatch = Beans.get(ProductionBatchRepository.class).find(productionBatch.getId());
    String name = I18n.get(ITranslation.WORK_IN_PROGRESS_VALUATION);
    String fileLink = ReportFactory.createReport(IReport.WORK_IN_PROGRESS_VALUATION, name + "-${date}").addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("Timezone", productionBatch.getCompany() != null ? productionBatch.getCompany().getTimezone() : null).addParam("companyId", productionBatch.getCompany() != null ? productionBatch.getCompany().getId() : 0).addParam("locationId", productionBatch.getWorkshopStockLocation() != null ? productionBatch.getWorkshopStockLocation().getId() : 0).addParam("editionDate", DateTimeFormatter.ofPattern("MMM d, yyyy, hh:mm a").format(productionBatch.getUpdatedOn())).generate().getFileLink();
    LOG.debug("Printing {}", name);
    response.setView(ActionView.define(name).add("html", fileLink).map());
}
Also used : ProductionBatch(com.axelor.apps.production.db.ProductionBatch)

Example 2 with ProductionBatch

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

the class ProductionBatchController method computeValuation.

public void computeValuation(ActionRequest request, ActionResponse response) {
    ProductionBatch productionBatch = request.getContext().asType(ProductionBatch.class);
    productionBatch = Beans.get(ProductionBatchRepository.class).find(productionBatch.getId());
    Batch batch = Beans.get(ProductionBatchService.class).computeValuation(productionBatch);
    if (batch != null) {
        response.setFlash(batch.getComments());
    }
    response.setReload(true);
}
Also used : ProductionBatchService(com.axelor.apps.production.service.batch.ProductionBatchService) ProductionBatch(com.axelor.apps.production.db.ProductionBatch) Batch(com.axelor.apps.base.db.Batch) ProductionBatch(com.axelor.apps.production.db.ProductionBatch)

Example 3 with ProductionBatch

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

the class BatchComputeWorkInProgressValuation method process.

@Override
protected void process() {
    ProductionBatch productionBatch = batch.getProductionBatch();
    Company company = productionBatch.getCompany();
    StockLocation workshopStockLocation = productionBatch.getWorkshopStockLocation();
    if (productionBatch.getValuationDate() == null) {
        productionBatch.setValuationDate(Beans.get(AppBaseService.class).getTodayDate(company));
    }
    LocalDate valuationDate = productionBatch.getValuationDate();
    List<ManufOrder> manufOrderList;
    Map<String, Object> bindValues = new HashMap<>();
    String domain = "(self.statusSelect = :statusSelectInProgress or self.statusSelect = :statusSelectStandBy " + "or (self.statusSelect = :statusSelectFinished " + "AND self.realEndDateT BETWEEN :valuationDateT AND :todayDateT))";
    bindValues.put("statusSelectInProgress", ManufOrderRepository.STATUS_IN_PROGRESS);
    bindValues.put("statusSelectStandBy", ManufOrderRepository.STATUS_STANDBY);
    bindValues.put("statusSelectFinished", ManufOrderRepository.STATUS_FINISHED);
    bindValues.put("valuationDateT", valuationDate.atStartOfDay());
    bindValues.put("todayDateT", appBaseService.getTodayDateTime().toLocalDateTime());
    if (company != null) {
        domain += " and self.company.id = :companyId";
        bindValues.put("companyId", company.getId());
    }
    if (workshopStockLocation != null) {
        domain += " and self.workshopStockLocation.id = :stockLocationId";
        bindValues.put("stockLocationId", workshopStockLocation.getId());
    }
    Query<ManufOrder> manufOrderQuery = Beans.get(ManufOrderRepository.class).all().filter(domain).bind(bindValues);
    int offset = 0;
    while (!(manufOrderList = manufOrderQuery.order("id").fetch(FETCH_LIMIT, offset)).isEmpty()) {
        for (ManufOrder manufOrder : manufOrderList) {
            ++offset;
            try {
                costSheetService.computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_WORK_IN_PROGRESS, valuationDate);
                incrementDone();
            } catch (Exception e) {
                incrementAnomaly();
                TraceBackService.trace(e, ExceptionOriginRepository.COST_SHEET, batch.getId());
            }
        }
        JPA.clear();
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) HashMap(java.util.HashMap) ProductionBatch(com.axelor.apps.production.db.ProductionBatch) LocalDate(java.time.LocalDate) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 4 with ProductionBatch

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

the class ProductionBatchService method run.

@Override
public Batch run(Model model) throws AxelorException {
    Batch batch;
    ProductionBatch productionBatch = (ProductionBatch) model;
    switch(productionBatch.getActionSelect()) {
        case ProductionBatchRepository.ACTION_COMPUTE_WORK_IN_PROGRESS_VALUATION:
            batch = computeValuation(productionBatch);
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BASE_BATCH_1), productionBatch.getActionSelect(), productionBatch.getCode());
    }
    return batch;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductionBatch(com.axelor.apps.production.db.ProductionBatch) Batch(com.axelor.apps.base.db.Batch) ProductionBatch(com.axelor.apps.production.db.ProductionBatch)

Example 5 with ProductionBatch

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

the class ProductionBatchManagementRepository method copy.

@Override
public ProductionBatch copy(ProductionBatch entity, boolean deep) {
    ProductionBatch copy = super.copy(entity, deep);
    copy.setBatchList(null);
    return copy;
}
Also used : ProductionBatch(com.axelor.apps.production.db.ProductionBatch)

Aggregations

ProductionBatch (com.axelor.apps.production.db.ProductionBatch)5 Batch (com.axelor.apps.base.db.Batch)2 Company (com.axelor.apps.base.db.Company)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)1 ProductionBatchService (com.axelor.apps.production.service.batch.ProductionBatchService)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 AxelorException (com.axelor.exception.AxelorException)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1