Search in sources :

Example 1 with ProductionConfig

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;
}
Also used : CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 2 with ProductionConfig

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Sequence(com.axelor.apps.base.db.Sequence)

Example 3 with ProductionConfig

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;
}
Also used : Company(com.axelor.apps.base.db.Company) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ProductService(com.axelor.apps.base.service.ProductService) Product(com.axelor.apps.base.db.Product) ProductionOrderService(com.axelor.apps.production.service.productionorder.ProductionOrderService) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) OperationOrder(com.axelor.apps.production.db.OperationOrder) BigDecimal(java.math.BigDecimal) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Transactional(com.google.inject.persist.Transactional)

Example 4 with ProductionConfig

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);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) ProductionConfigRepository(com.axelor.apps.production.db.repo.ProductionConfigRepository) Transactional(com.google.inject.persist.Transactional)

Aggregations

ProductionConfig (com.axelor.apps.production.db.ProductionConfig)4 Transactional (com.google.inject.persist.Transactional)3 Company (com.axelor.apps.base.db.Company)2 OperationOrder (com.axelor.apps.production.db.OperationOrder)2 CostSheetService (com.axelor.apps.production.service.costsheet.CostSheetService)2 Product (com.axelor.apps.base.db.Product)1 Sequence (com.axelor.apps.base.db.Sequence)1 ProductService (com.axelor.apps.base.service.ProductService)1 ProductionConfigRepository (com.axelor.apps.production.db.repo.ProductionConfigRepository)1 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)1 ProductionConfigService (com.axelor.apps.production.service.config.ProductionConfigService)1 ProductionOrderService (com.axelor.apps.production.service.productionorder.ProductionOrderService)1 AxelorException (com.axelor.exception.AxelorException)1 BigDecimal (java.math.BigDecimal)1