Search in sources :

Example 16 with ManufOrder

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

the class StockMoveLineController method compute.

public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
    StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
    Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
    if (!stockMove.isPresent()) {
        Context parentContext = request.getContext().getParent();
        if (parentContext.getContextClass().equals(StockMove.class)) {
            stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
        } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
            ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
            ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
            stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
        }
        if (!stockMove.isPresent()) {
            return;
        }
    }
    stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
    response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
    response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
    response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 17 with ManufOrder

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

the class StockMoveLineController method setProductInfo.

/**
 * Called from stock move line form. Fill product info using the company either from the stock
 * move line, from the parent stock move or the parent manuf order.
 *
 * @param request
 * @param response
 */
public void setProductInfo(ActionRequest request, ActionResponse response) {
    StockMoveLine stockMoveLine;
    try {
        stockMoveLine = request.getContext().asType(StockMoveLine.class);
        Company company;
        StockMove stockMove = stockMoveLine.getStockMove();
        if (stockMove == null) {
            Context parentContext = request.getContext().getParent();
            if (parentContext.getContextClass().equals(StockMove.class)) {
                stockMove = parentContext.asType(StockMove.class);
                company = stockMove.getCompany();
            } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
                ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
                company = manufOrder.getCompany();
            } else if (parentContext.getContextClass().equals(OperationOrder.class)) {
                OperationOrder operationOrder = parentContext.asType(OperationOrder.class);
                if (operationOrder.getManufOrder() == null) {
                    return;
                }
                company = operationOrder.getManufOrder().getCompany();
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.STOCK_MOVE_LINE_UNKNOWN_PARENT_CONTEXT);
            }
        } else {
            company = stockMove.getCompany();
        }
        if (stockMoveLine.getProduct() == null) {
            stockMoveLine = new StockMoveLine();
            response.setValues(Mapper.toMap(stockMoveLine));
            return;
        }
        Beans.get(StockMoveLineService.class).setProductInfo(stockMove, stockMoveLine, company);
        response.setValues(stockMoveLine);
    } catch (Exception e) {
        stockMoveLine = new StockMoveLine();
        response.setValues(Mapper.toMap(stockMoveLine));
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) OperationOrder(com.axelor.apps.production.db.OperationOrder) AxelorException(com.axelor.exception.AxelorException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 18 with ManufOrder

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

the class ManufOrderServiceBusinessImpl method createManufOrder.

@Override
public ManufOrder createManufOrder(Product product, BigDecimal qty, int priority, boolean isToInvoice, Company company, BillOfMaterial billOfMaterial, LocalDateTime plannedStartDateT, LocalDateTime plannedEndDateT) throws AxelorException {
    ManufOrder manufOrder = super.createManufOrder(product, qty, priority, isToInvoice, company, billOfMaterial, plannedStartDateT, plannedEndDateT);
    AppProductionService appProductionService = Beans.get(AppProductionService.class);
    if (!appProductionService.isApp("production") || !appProductionService.getAppProduction().getManageBusinessProduction()) {
        return manufOrder;
    }
    manufOrder.setIsToInvoice(isToInvoice);
    return manufOrder;
}
Also used : ManufOrder(com.axelor.apps.production.db.ManufOrder) AppProductionService(com.axelor.apps.production.service.app.AppProductionService)

Example 19 with ManufOrder

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

the class ManufOrderBusinessController method propagateIsToInvoice.

public void propagateIsToInvoice(ActionRequest request, ActionResponse response) {
    ManufOrderServiceBusinessImpl manufOrderService = Beans.get(ManufOrderServiceBusinessImpl.class);
    ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
    manufOrderService.propagateIsToInvoice(Beans.get(ManufOrderRepository.class).find(manufOrder.getId()));
    response.setReload(true);
}
Also used : ManufOrderServiceBusinessImpl(com.axelor.apps.businessproduction.service.ManufOrderServiceBusinessImpl) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 20 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder 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)

Aggregations

ManufOrder (com.axelor.apps.production.db.ManufOrder)44 AxelorException (com.axelor.exception.AxelorException)30 IOException (java.io.IOException)22 BirtException (org.eclipse.birt.core.exception.BirtException)22 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)17 ManufOrderService (com.axelor.apps.production.service.manuforder.ManufOrderService)12 BigDecimal (java.math.BigDecimal)12 ArrayList (java.util.ArrayList)12 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)11 List (java.util.List)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ManufOrderWorkflowService (com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService)10 Transactional (com.google.inject.persist.Transactional)10 Beans (com.axelor.inject.Beans)9 Company (com.axelor.apps.base.db.Company)8 Product (com.axelor.apps.base.db.Product)8 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)8 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)8 I18n (com.axelor.i18n.I18n)8