use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.
the class SaleOrderLineServiceSupplyChainImpl method createSaleOrderLine.
@Override
public SaleOrderLine createSaleOrderLine(PackLine packLine, SaleOrder saleOrder, BigDecimal packQty, BigDecimal conversionRate, Integer sequence) {
SaleOrderLine soLine = super.createSaleOrderLine(packLine, saleOrder, packQty, conversionRate, sequence);
if (soLine != null && soLine.getProduct() != null) {
soLine.setSaleSupplySelect(soLine.getProduct().getSaleSupplySelect());
getAndComputeAnalyticDistribution(soLine, saleOrder);
if (ObjectUtils.notEmpty(soLine.getAnalyticMoveLineList())) {
soLine.getAnalyticMoveLineList().stream().forEach(analyticMoveLine -> analyticMoveLine.setSaleOrderLine(soLine));
}
try {
SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
if (supplyChainConfig.getAutoRequestReservedQty()) {
Beans.get(ReservedQtyService.class).requestQty(soLine);
}
} catch (AxelorException e) {
TraceBackService.trace(e);
}
}
return soLine;
}
use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedQuantityInToStockLocation.
@Override
public void updateRequestedQuantityInToStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal qty) throws AxelorException {
if (product == null || !product.getStockManaged()) {
return;
}
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
if (stockLocationLine == null) {
return;
}
Company company = stockLocationLine.getStockLocation().getCompany();
SupplyChainConfig supplyChainConfig = supplychainConfigService.getSupplyChainConfig(company);
if (toStatus == StockMoveRepository.STATUS_REALIZED && supplyChainConfig.getAutoAllocateOnReceipt()) {
reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qty);
}
updateRequestedReservedQty(stockLocationLine);
checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.
the class StockMoveController method allocateAll.
/**
* Called from stock move form view, on available qty boolean change. Only called if the user
* accepted to allocate everything. Call {@link
* StockMoveReservedQtyService#allocateAll(StockMove)}.
*
* @param request
* @param response
*/
public void allocateAll(ActionRequest request, ActionResponse response) {
try {
StockMove stockMove = request.getContext().asType(StockMove.class);
Company company = stockMove.getCompany();
if (company == null) {
return;
}
SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
if (!Beans.get(AppSupplychainService.class).getAppSupplychain().getManageStockReservation() || !stockMove.getAvailabilityRequest() || !supplyChainConfig.getAutoAllocateOnAvailabilityRequest()) {
return;
}
Beans.get(StockMoveReservedQtyService.class).allocateAll(stockMove);
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method openInvoicingWizard.
public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
try {
response.setReload(true);
StockMove stockMove = request.getContext().asType(StockMove.class);
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
Company company = stockMove.getCompany();
SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
// open wizard view for partial invoicing
response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
} else if (!stockMoveLines.isEmpty()) {
// invoice everything if config is disabled.
Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
if (invoice != null) {
response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
}
} else {
response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.
the class SaleOrderStockServiceImpl method createStockMove.
protected Optional<StockMove> createStockMove(SaleOrder saleOrder, LocalDate estimatedDeliveryDate, List<SaleOrderLine> saleOrderLineList) throws AxelorException {
StockMove stockMove = this.createStockMove(saleOrder, saleOrder.getCompany(), estimatedDeliveryDate);
stockMove.setDeliveryCondition(saleOrder.getDeliveryCondition());
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
if (saleOrderLine.getProduct() != null) {
BigDecimal qty = saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine);
if (qty.signum() > 0 && !existActiveStockMoveForSaleOrderLine(saleOrderLine)) {
createStockMoveLine(stockMove, saleOrderLine, qty);
}
}
}
if (stockMove.getStockMoveLineList() == null || stockMove.getStockMoveLineList().isEmpty()) {
return Optional.empty();
}
if (stockMove.getStockMoveLineList().stream().noneMatch(stockMoveLine -> stockMoveLine.getSaleOrderLine() != null && stockMoveLine.getSaleOrderLine().getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL)) {
stockMove.setFullySpreadOverLogisticalFormsFlag(true);
}
boolean isNeedingConformityCertificate = saleOrder.getIsNeedingConformityCertificate();
stockMove.setIsNeedingConformityCertificate(isNeedingConformityCertificate);
if (isNeedingConformityCertificate) {
stockMove.setSignatoryUser(stockConfigService.getStockConfig(stockMove.getCompany()).getSignatoryUser());
}
SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
if (supplychainConfig.getDefaultEstimatedDate() != null && supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()));
} else if (supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()).plusDays(supplychainConfig.getNumberOfDays().longValue()));
}
setReservationDateTime(stockMove, saleOrder);
stockMoveService.plan(stockMove);
return Optional.of(stockMove);
}
Aggregations