Search in sources :

Example 1 with ProductionOrder

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

the class ProductionOrderSaleOrderServiceImpl method generateProductionOrder.

@Override
@Transactional(rollbackOn = { AxelorException.class })
public List<Long> generateProductionOrder(SaleOrder saleOrder) throws AxelorException {
    boolean oneProdOrderPerSO = appProductionService.getAppProduction().getOneProdOrderPerSO();
    List<Long> productionOrderIdList = new ArrayList<>();
    if (saleOrder.getSaleOrderLineList() == null) {
        return productionOrderIdList;
    }
    ProductionOrder productionOrder = null;
    for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
        if (productionOrder == null || !oneProdOrderPerSO) {
            productionOrder = this.createProductionOrder(saleOrder);
        }
        productionOrder = this.generateManufOrders(productionOrder, saleOrderLine);
        if (productionOrder != null && !productionOrderIdList.contains(productionOrder.getId())) {
            productionOrderIdList.add(productionOrder.getId());
        }
    }
    return productionOrderIdList;
}
Also used : ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) Transactional(com.google.inject.persist.Transactional)

Example 2 with ProductionOrder

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

the class ProductionOrderServiceImpl method createProductionOrder.

public ProductionOrder createProductionOrder(SaleOrder saleOrder) throws AxelorException {
    ProductionOrder productionOrder = new ProductionOrder(this.getProductionOrderSeq());
    if (saleOrder != null) {
        productionOrder.setClientPartner(saleOrder.getClientPartner());
        productionOrder.setSaleOrder(saleOrder);
    }
    return productionOrder;
}
Also used : ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Example 3 with ProductionOrder

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

the class ProductionOrderSaleOrderServiceBusinessImpl method createProductionOrder.

@Override
protected ProductionOrder createProductionOrder(SaleOrder saleOrder) throws AxelorException {
    ProductionOrder productionOrder = super.createProductionOrder(saleOrder);
    AppProductionService appProductionService = Beans.get(AppProductionService.class);
    if (appProductionService.isApp("production") && appProductionService.getAppProduction().getManageBusinessProduction()) {
        productionOrder.setProject(saleOrder.getProject());
    }
    return productionOrder;
}
Also used : ProductionOrder(com.axelor.apps.production.db.ProductionOrder) AppProductionService(com.axelor.apps.production.service.app.AppProductionService)

Example 4 with ProductionOrder

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

the class ProductionOrderWizardServiceBusinessImpl method validate.

@Override
@SuppressWarnings("unchecked")
public Long validate(Context context) throws AxelorException {
    AppProductionService appProductionService = Beans.get(AppProductionService.class);
    if (!appProductionService.isApp("production") || !appProductionService.getAppProduction().getManageBusinessProduction()) {
        return super.validate(context);
    }
    Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial");
    BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue());
    BigDecimal qty = new BigDecimal((String) context.get("qty"));
    Product product = null;
    if (context.get("product") != null) {
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        product = productRepo.find(((Integer) productContext.get("id")).longValue());
    } else {
        product = billOfMaterial.getProduct();
    }
    ZonedDateTime startDateT, endDateT = null;
    if (context.containsKey("_startDate") && context.get("_startDate") != null) {
        startDateT = ZonedDateTime.parse(context.get("_startDate").toString(), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
    } else {
        startDateT = appProductionService.getTodayDateTime();
    }
    if (context.containsKey("_endDate") && context.get("_endDate") != null) {
        endDateT = ZonedDateTime.parse(context.get("_endDate").toString(), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
    }
    Project project = null;
    if (context.get("business_id") != null) {
        project = Beans.get(ProjectRepository.class).find(((Integer) context.get("business_id")).longValue());
    }
    ProductionOrder productionOrder = productionOrderServiceBusinessImpl.generateProductionOrder(product, billOfMaterial, qty, project, startDateT.toLocalDateTime(), endDateT != null ? endDateT.toLocalDateTime() : null, null);
    if (productionOrder != null) {
        return productionOrder.getId();
    } else {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_2));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Project(com.axelor.apps.project.db.Project) ZonedDateTime(java.time.ZonedDateTime) Map(java.util.Map) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Example 5 with ProductionOrder

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

the class ProductionOrderBusinessController method generateSaleOrder.

public void generateSaleOrder(ActionRequest request, ActionResponse response) throws AxelorException {
    ProductionOrder productionOrder = request.getContext().asType(ProductionOrder.class);
    Beans.get(ProductionOrderSaleOrderServiceBusinessImpl.class).createSaleOrder(Beans.get(ProductionOrderRepository.class).find(productionOrder.getId()));
    response.setReload(true);
}
Also used : ProductionOrderSaleOrderServiceBusinessImpl(com.axelor.apps.businessproduction.service.ProductionOrderSaleOrderServiceBusinessImpl) ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Aggregations

ProductionOrder (com.axelor.apps.production.db.ProductionOrder)9 Transactional (com.google.inject.persist.Transactional)4 Product (com.axelor.apps.base.db.Product)3 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)3 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)3 AxelorException (com.axelor.exception.AxelorException)3 BigDecimal (java.math.BigDecimal)3 Company (com.axelor.apps.base.db.Company)1 Sequence (com.axelor.apps.base.db.Sequence)1 Unit (com.axelor.apps.base.db.Unit)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)1 ProductVariantService (com.axelor.apps.base.service.ProductVariantService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 SequenceService (com.axelor.apps.base.service.administration.SequenceService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ProductionOrderSaleOrderServiceBusinessImpl (com.axelor.apps.businessproduction.service.ProductionOrderSaleOrderServiceBusinessImpl)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 OperationOrder (com.axelor.apps.production.db.OperationOrder)1 ProdProcess (com.axelor.apps.production.db.ProdProcess)1