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());
}
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);
}
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();
}
}
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;
}
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;
}
Aggregations