use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveLineStockRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
Long stockMoveLineId = (Long) json.get("id");
StockMoveLine stockMoveLine = find(stockMoveLineId);
StockMove stockMove = stockMoveLine.getStockMove();
if (stockMove == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
return super.populate(json, context);
}
if (stockMove.getStatusSelect() < StockMoveRepository.STATUS_REALIZED) {
Beans.get(StockMoveLineService.class).setAvailableStatus(stockMoveLine);
json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
}
return super.populate(json, context);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveManagementRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
Long stockMoveId = (Long) json.get("id");
StockMove stockMove = find(stockMoveId);
if (stockMove.getStatusSelect() > STATUS_PLANNED || stockMove.getStockMoveLineList() == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
return super.populate(json, context);
}
int available = 0, availableForProduct = 0, missing = 0;
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
if (stockMoveLine != null && stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getProductTypeSelect() != null && stockMoveLine.getProduct().getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_SERVICE)) {
continue;
}
Beans.get(StockMoveLineService.class).updateAvailableQty(stockMoveLine, stockMove.getFromStockLocation());
Product product = stockMoveLine.getProduct();
if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) >= 0 || product != null && !product.getStockManaged()) {
available++;
} else if (stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) >= 0) {
availableForProduct++;
} else if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) < 0 && stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) < 0) {
missing++;
}
}
if ((available > 0 || availableForProduct > 0) && missing == 0) {
json.put("availableStatusSelect", StockMoveRepository.STATUS_AVAILABLE);
} else if ((available > 0 || availableForProduct > 0) && missing > 0) {
json.put("availableStatusSelect", StockMoveRepository.STATUS_PARTIALLY_AVAILABLE);
} else if (available == 0 && availableForProduct == 0 && missing > 0) {
json.put("availableStatusSelect", StockMoveRepository.STATUS_UNAVAILABLE);
}
return super.populate(json, context);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveManagementRepository method copy.
@Override
public StockMove copy(StockMove entity, boolean deep) {
StockMove copy = super.copy(entity, deep);
copy.setStatusSelect(STATUS_DRAFT);
copy.setStockMoveSeq(null);
copy.setName(null);
copy.setRealDate(null);
copy.setPickingEditDate(null);
copy.setPickingIsEdited(false);
copy.setAvailabilityRequest(false);
copy.setSupplierShipmentDate(null);
copy.setSupplierShipmentRef(null);
copy.setAvailabilityRequest(false);
copy.setFullySpreadOverLogisticalFormsFlag(false);
return copy;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class SaleOrderController method notifyStockMoveCreated.
public void notifyStockMoveCreated(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
StockMoveRepository stockMoveRepo = Beans.get(StockMoveRepository.class);
StockMove stockMove = stockMoveRepo.all().filter("self.originTypeSelect = ?1 AND self.originId = ?2 AND self.statusSelect = ?3", "com.axelor.apps.sale.db.SaleOrder", saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetchOne();
if (stockMove != null) {
response.setNotify(String.format(I18n.get(IExceptionMessage.SALE_ORDER_STOCK_MOVE_CREATED), stockMove.getStockMoveSeq()));
}
}
use of com.axelor.apps.stock.db.StockMove 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;
}
Aggregations