Search in sources :

Example 1 with SaleOrderWorkflowService

use of com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService in project axelor-open-suite by axelor.

the class OpportunitySaleOrderController method cancelSaleOrders.

public void cancelSaleOrders(ActionRequest request, ActionResponse response) {
    Opportunity opportunity = request.getContext().asType(Opportunity.class);
    SaleOrderWorkflowService saleOrderWorkflowService = Beans.get(SaleOrderWorkflowService.class);
    if (opportunity.getSalesStageSelect() == OpportunityRepository.SALES_STAGE_CLOSED_LOST) {
        List<SaleOrder> saleOrderList = opportunity.getSaleOrderList();
        if (saleOrderList != null && !saleOrderList.isEmpty()) {
            for (SaleOrder saleOrder : saleOrderList) {
                if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION || saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_FINALIZED_QUOTATION) {
                    saleOrderWorkflowService.cancelSaleOrder(saleOrder, null, opportunity.getName());
                }
            }
        }
    }
}
Also used : SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) Opportunity(com.axelor.apps.crm.db.Opportunity) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 2 with SaleOrderWorkflowService

use of com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService 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)

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 SaleOrderWorkflowService (com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService)2 Invoice (com.axelor.apps.account.db.Invoice)1 Product (com.axelor.apps.base.db.Product)1 Opportunity (com.axelor.apps.crm.db.Opportunity)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)1 StockMoveService (com.axelor.apps.stock.service.StockMoveService)1 SaleOrderInvoiceService (com.axelor.apps.supplychain.service.SaleOrderInvoiceService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1