use of com.axelor.apps.production.db.ProductionConfig in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method partialFinish.
/**
* Allows to finish partially a manufacturing order, by realizing current stock move and planning
* the difference with the planned prodproducts.
*
* @param manufOrder
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public boolean partialFinish(ManufOrder manufOrder) throws AxelorException {
if (manufOrder.getIsConsProOnOperation()) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_PLANNED) {
operationOrderWorkflowService.start(operationOrder);
}
}
}
Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
Beans.get(ManufOrderStockMoveService.class).partialFinish(manufOrder);
ProductionConfig productionConfig = manufOrder.getCompany() != null ? productionConfigRepo.findByCompany(manufOrder.getCompany()) : null;
if (productionConfig != null && productionConfig.getPartFinishMoAutomaticEmail()) {
return this.sendMail(manufOrder, productionConfig.getPartFinishMoMessageTemplate());
}
return true;
}
use of com.axelor.apps.production.db.ProductionConfig in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method getManufOrderSeq.
@Override
public String getManufOrderSeq(ManufOrder manufOrder) throws AxelorException {
ProductionConfigService productionConfigService = Beans.get(ProductionConfigService.class);
ProductionConfig productionConfig = productionConfigService.getProductionConfig(manufOrder.getCompany());
Sequence sequence = productionConfigService.getManufOrderSequence(productionConfig, manufOrder.getWorkshopStockLocation());
String seq = sequenceService.getSequenceNumber(sequence);
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MANUF_ORDER_SEQ));
}
return seq;
}
use of com.axelor.apps.production.db.ProductionConfig in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method finish.
@Transactional(rollbackOn = { Exception.class })
public boolean finish(ManufOrder manufOrder) throws AxelorException {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_FINISHED) {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_IN_PROGRESS && operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_STANDBY) {
operationOrderWorkflowService.start(operationOrder);
}
operationOrderWorkflowService.finish(operationOrder);
}
}
}
// create cost sheet
Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_END_OF_PRODUCTION, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
// update price in product
Product product = manufOrder.getProduct();
Company company = manufOrder.getCompany();
if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_FORECAST) {
productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
} else if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_REAL) {
BigDecimal costPrice = computeOneUnitProductionPrice(manufOrder);
if (costPrice.signum() != 0) {
productCompanyService.set(product, "lastProductionPrice", costPrice, company);
}
} else {
// default value is forecast
productCompanyService.set(product, "realOrEstimatedPriceSelect", ProductRepository.PRICE_METHOD_FORECAST, company);
productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
}
// update costprice in product
if (((Integer) productCompanyService.get(product, "costTypeSelect", company)) == ProductRepository.COST_TYPE_LAST_PRODUCTION_PRICE) {
productCompanyService.set(product, "costPrice", (BigDecimal) productCompanyService.get(product, "lastProductionPrice", company), company);
if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", company)) {
Beans.get(ProductService.class).updateSalePrice(product, company);
}
}
manufOrderStockMoveService.finish(manufOrder);
manufOrder.setRealEndDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_FINISHED);
manufOrder.setEndTimeDifference(new BigDecimal(ChronoUnit.MINUTES.between(manufOrder.getPlannedEndDateT(), manufOrder.getRealEndDateT())));
manufOrderRepo.save(manufOrder);
Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
ProductionConfig productionConfig = manufOrder.getCompany() != null ? productionConfigRepo.findByCompany(manufOrder.getCompany()) : null;
if (productionConfig != null && productionConfig.getFinishMoAutomaticEmail()) {
return this.sendMail(manufOrder, productionConfig.getFinishMoMessageTemplate());
}
return true;
}
use of com.axelor.apps.production.db.ProductionConfig in project axelor-open-suite by axelor.
the class AppProductionServiceImpl method generateProductionConfigurations.
@Override
@Transactional
public void generateProductionConfigurations() {
List<Company> companies = Query.of(Company.class).filter("self.productionConfig is null").fetch();
for (Company company : companies) {
ProductionConfig productionConfig = new ProductionConfig();
productionConfig.setCompany(company);
Beans.get(ProductionConfigRepository.class).save(productionConfig);
}
}
Aggregations