Search in sources :

Example 1 with StockMoveService

use of com.axelor.apps.stock.service.StockMoveService in project axelor-open-suite by axelor.

the class ImportSupplyChain method importPurchaseOrderFromSupplyChain.

@Transactional
public Object importPurchaseOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        PurchaseOrder purchaseOrder = (PurchaseOrder) bean;
        int status = purchaseOrder.getStatusSelect();
        purchaseOrder = (PurchaseOrder) importPurchaseOrder.importPurchaseOrder(bean, values);
        for (PurchaseOrderLine line : purchaseOrder.getPurchaseOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(purchaseOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (status == PurchaseOrderRepository.STATUS_VALIDATED || status == PurchaseOrderRepository.STATUS_FINISHED) {
            purchaseOrderWorkflowService.validatePurchaseOrder(purchaseOrder);
        }
        if (status == PurchaseOrderRepository.STATUS_FINISHED) {
            List<Long> idList = purchaseOrderStockServiceImpl.createStockMoveFromPurchaseOrder(purchaseOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                stockMoveService.copyQtyToRealQty(stockMove);
                stockMoveService.realize(stockMove);
                stockMove.setRealDate(purchaseOrder.getDeliveryDate());
            }
            purchaseOrder.setValidationDate(purchaseOrder.getOrderDate());
            purchaseOrder.setValidatedByUser(AuthUtils.getUser());
            purchaseOrder.setSupplierPartner(purchaseOrderService.validateSupplier(purchaseOrder));
            Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
            String prefixSupplierSeq = "INV000";
            invoice.setSupplierInvoiceNb(prefixSupplierSeq + purchaseOrder.getImportId());
            invoice.setInternalReference(purchaseOrder.getInternalReference());
            LocalDate date;
            if (purchaseOrder.getValidationDate() != null) {
                date = purchaseOrder.getValidationDate();
            } else {
                date = Beans.get(AppBaseService.class).getTodayDate(purchaseOrder.getCompany());
            }
            invoice.setInvoiceDate(date);
            invoice.setOriginDate(date.minusDays(15));
            invoiceService.validateAndVentilate(invoice);
            purchaseOrderWorkflowService.finishPurchaseOrder(purchaseOrder);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ImportPurchaseOrder(com.axelor.apps.purchase.script.ImportPurchaseOrder) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService) Transactional(com.google.inject.persist.Transactional)

Example 2 with StockMoveService

use of com.axelor.apps.stock.service.StockMoveService in project axelor-open-suite by axelor.

the class ImportSupplyChain method importSaleOrderFromSupplyChain.

@Transactional
public Object importSaleOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        SaleOrderWorkflowService saleOrderWorkflowService = Beans.get(SaleOrderWorkflowService.class);
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        SaleOrder saleOrder = (SaleOrder) importSaleOrder.importSaleOrder(bean, values);
        for (SaleOrderLine line : saleOrder.getSaleOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(saleOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_FINALIZED_QUOTATION) {
            // taskSaleOrderService.createTasks(saleOrder); TODO once we will have done the generation//
            // of tasks in project module
            saleOrderWorkflowService.confirmSaleOrder(saleOrder);
            // Beans.get(SaleOrderPurchaseService.class).createPurchaseOrders(saleOrder);
            // productionOrderSaleOrderService.generateProductionOrder(saleOrder);
            // saleOrder.setClientPartner(saleOrderWorkflowService.validateCustomer(saleOrder));
            // Generate invoice from sale order
            Invoice invoice = Beans.get(SaleOrderInvoiceService.class).generateInvoice(saleOrder);
            if (saleOrder.getConfirmationDateTime() != null) {
                invoice.setInvoiceDate(saleOrder.getConfirmationDateTime().toLocalDate());
            } else {
                invoice.setInvoiceDate(Beans.get(AppBaseService.class).getTodayDate(saleOrder.getCompany()));
            }
            invoiceService.validateAndVentilate(invoice);
            List<Long> idList = saleOrderStockService.createStocksMovesFromSaleOrder(saleOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
                    stockMoveService.copyQtyToRealQty(stockMove);
                    stockMoveService.validate(stockMove);
                    if (saleOrder.getConfirmationDateTime() != null) {
                        stockMove.setRealDate(saleOrder.getConfirmationDateTime().toLocalDate());
                    }
                }
            }
        }
        saleOrderRepo.save(saleOrder);
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 3 with StockMoveService

use of com.axelor.apps.stock.service.StockMoveService in project axelor-open-suite by axelor.

the class SaleOrderServiceSupplychainImpl method enableEditOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public boolean enableEditOrder(SaleOrder saleOrder) throws AxelorException {
    boolean checkAvailabiltyRequest = super.enableEditOrder(saleOrder);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return checkAvailabiltyRequest;
    }
    List<StockMove> allStockMoves = Beans.get(StockMoveRepository.class).findAllBySaleOrderAndStatus(StockMoveRepository.ORIGIN_SALE_ORDER, saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetch();
    List<StockMove> stockMoves = !allStockMoves.isEmpty() ? allStockMoves.stream().filter(stockMove -> !stockMove.getAvailabilityRequest()).collect(Collectors.toList()) : allStockMoves;
    checkAvailabiltyRequest = stockMoves.size() != allStockMoves.size() ? true : checkAvailabiltyRequest;
    if (!stockMoves.isEmpty()) {
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        CancelReason cancelReason = appSupplychain.getCancelReasonOnChangingSaleOrder();
        if (cancelReason == null) {
            throw new AxelorException(appSupplychain, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.SUPPLYCHAIN_MISSING_CANCEL_REASON_ON_CHANGING_SALE_ORDER);
        }
        for (StockMove stockMove : stockMoves) {
            stockMoveService.cancel(stockMove, cancelReason);
            stockMove.setArchived(true);
            for (StockMoveLine stockMoveline : stockMove.getStockMoveLineList()) {
                stockMoveline.setSaleOrderLine(null);
                stockMoveline.setArchived(true);
            }
        }
    }
    return checkAvailabiltyRequest;
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) CancelReason(com.axelor.apps.base.db.CancelReason) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 4 with StockMoveService

use of com.axelor.apps.stock.service.StockMoveService in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method generateWasteStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
    StockMove wasteStockMove = null;
    Company company = manufOrder.getCompany();
    if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
        return wasteStockMove;
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
    StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
    wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
    for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
        stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
    }
    stockMoveService.validate(wasteStockMove);
    manufOrder.setWasteStockMove(wasteStockMove);
    return wasteStockMove;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) Transactional(com.google.inject.persist.Transactional)

Example 5 with StockMoveService

use of com.axelor.apps.stock.service.StockMoveService in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method updateStockMoveFromManufOrder.

@Override
public void updateStockMoveFromManufOrder(List<StockMoveLine> stockMoveLineList, StockMove stockMove) throws AxelorException {
    if (stockMoveLineList == null) {
        return;
    }
    // add missing lines in stock move
    stockMoveLineList.stream().filter(stockMoveLine -> stockMoveLine.getStockMove() == null).forEach(stockMove::addStockMoveLineListItem);
    // remove lines in stock move removed in manuf order
    if (stockMove.getStockMoveLineList() != null) {
        stockMove.getStockMoveLineList().removeIf(stockMoveLine -> !stockMoveLineList.contains(stockMoveLine));
    }
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    // update stock location by cancelling then planning stock move.
    stockMoveService.cancel(stockMove);
    stockMoveService.plan(stockMove);
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductVariantService(com.axelor.apps.base.service.ProductVariantService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Joiner(com.google.common.base.Joiner) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LocalDateTime(java.time.LocalDateTime) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) StringTool(com.axelor.apps.tool.StringTool) Sequence(com.axelor.apps.base.db.Sequence) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MoreObjects(com.google.common.base.MoreObjects) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) Comparator(java.util.Comparator) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Collections(java.util.Collections) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)6 StockMoveService (com.axelor.apps.stock.service.StockMoveService)6 AxelorException (com.axelor.exception.AxelorException)5 Transactional (com.google.inject.persist.Transactional)5 Product (com.axelor.apps.base.db.Product)3 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)3 Invoice (com.axelor.apps.account.db.Invoice)2 Company (com.axelor.apps.base.db.Company)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 ProdProduct (com.axelor.apps.production.db.ProdProduct)2 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)2 OperationOrderStockMoveService (com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService)2 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 StockConfig (com.axelor.apps.stock.db.StockConfig)2 StockLocation (com.axelor.apps.stock.db.StockLocation)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)2 CancelReason (com.axelor.apps.base.db.CancelReason)1 Sequence (com.axelor.apps.base.db.Sequence)1 Unit (com.axelor.apps.base.db.Unit)1