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());
}
}
}
}
}
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;
}
Aggregations