use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class BatchOutgoingStockMoveInvoicing method process.
@Override
protected void process() {
SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
List<Long> anomalyList = Lists.newArrayList(0L);
SaleOrderRepository saleRepo = Beans.get(SaleOrderRepository.class);
TypedQuery<StockMove> query = JPA.em().createQuery("SELECT self FROM StockMove self " + "WHERE self.statusSelect = :statusSelect " + "AND self.originTypeSelect LIKE :typeSaleOrder " + "AND self.invoicingStatusSelect != :invoicingStatusSelect " + "AND (SELECT count(invoice.id) FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusCanceled AND invoice MEMBER OF self.invoiceSet) = 0" + "AND self.id NOT IN (:anomalyList) " + "AND self.partner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ") " + "AND :batch NOT MEMBER OF self.batchSet " + "ORDER BY self.id", StockMove.class).setParameter("statusSelect", StockMoveRepository.STATUS_REALIZED).setParameter("typeSaleOrder", StockMoveRepository.ORIGIN_SALE_ORDER).setParameter("invoiceStatusCanceled", InvoiceRepository.STATUS_CANCELED).setParameter("invoicingStatusSelect", StockMoveRepository.STATUS_DELAYED_INVOICE).setParameter("anomalyList", anomalyList).setParameter("batch", batch).setMaxResults(FETCH_LIMIT);
List<StockMove> stockMoveList;
while (!(stockMoveList = query.getResultList()).isEmpty()) {
for (StockMove stockMove : stockMoveList) {
try {
stockMoveInvoiceService.createInvoiceFromSaleOrder(stockMove, saleRepo.find(stockMove.getOriginId()), null);
updateStockMove(stockMove);
} catch (Exception e) {
incrementAnomaly();
anomalyList.add(stockMove.getId());
query.setParameter("anomalyList", anomalyList);
TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
break;
}
}
JPA.clear();
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class SupplierViewController method getNextDelivery.
public void getNextDelivery(ActionRequest request, ActionResponse response) {
try {
SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
User user = supplierViewService.getSupplierUser();
String domain = Beans.get(SupplierViewService.class).getNextDeliveryOfSupplier(user);
StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(domain).fetchOne();
if (stockMove != null) {
response.setView(ActionView.define(I18n.get("Next delivery")).model(StockMove.class.getName()).add("form", "stock-move-supplier-form").domain(domain).context("_showRecord", stockMove.getId()).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class SupplierViewServiceImpl method updateSupplierViewIndicators.
@Override
public Map<String, Object> updateSupplierViewIndicators() {
User user = getSupplierUser();
Map<String, Object> map = new HashMap<>();
/* PurchaseOrder */
map.put("$orders", getCount(PurchaseOrder.class, getPurchaseOrdersOfSupplier(user)));
map.put("$quotationInProgress", getCount(PurchaseOrder.class, getPurchaseQuotationsInProgressOfSupplier(user)));
PurchaseOrder lastOrder = getData(PurchaseOrder.class, getLastPurchaseOrderOfSupplier(user));
map.put("$lastOrder", lastOrder != null ? lastOrder.getValidationDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
/* StockMove */
StockMove stockMoveLastDelivery = getData(StockMove.class, getLastDeliveryOfSupplier(user));
map.put("$lastDelivery", stockMoveLastDelivery != null ? stockMoveLastDelivery.getRealDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
StockMove stockMoveNextDelivery = getData(StockMove.class, getNextDeliveryOfSupplier(user));
map.put("$nextDelivery", stockMoveNextDelivery != null ? stockMoveNextDelivery.getEstimatedDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
map.put("$deliveriesToPrepare", getCount(StockMove.class, getDeliveriesToPrepareOfSupplier(user)));
/* Invoice */
map.put("$overdueInvoices", getCount(Invoice.class, getOverdueInvoicesOfSupplier(user)));
map.put("$awaitingInvoices", getCount(Invoice.class, getAwaitingInvoicesOfSupplier(user)));
map.put("$totalRemaining", getCount(Invoice.class, getTotalRemainingOfSupplier(user)));
return map;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method updateProducedStockMoveFromManufOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateProducedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
List<StockMoveLine> producedStockMoveLineList = manufOrder.getProducedStockMoveLineList();
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getOutStockMoveList());
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = manufOrderStockMoveService._createToProduceStockMove(manufOrder, manufOrder.getCompany());
manufOrder.addOutStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
updateStockMoveFromManufOrder(producedStockMoveLineList, stockMove);
}
use of com.axelor.apps.stock.db.StockMove 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;
}
Aggregations