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