use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class SaleOrderLineController method supplierPartnerDomain.
/**
* Called from sale order line form. Set domain for supplier partner.
*
* @param request
* @param response
*/
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
String domain = "self.isContact = false AND self.isSupplier = true";
Product product = saleOrderLine.getProduct();
if (product != null) {
List<Long> authorizedPartnerIdsList = Beans.get(SaleOrderLineServiceSupplyChain.class).getSupplierPartnerList(saleOrderLine);
if (authorizedPartnerIdsList.isEmpty()) {
response.setAttr("supplierPartner", "domain", "self.id IN (0)");
return;
} else {
domain += String.format(" AND self.id IN (%s)", authorizedPartnerIdsList.stream().map(Object::toString).collect(Collectors.joining(",")));
}
}
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (saleOrder == null) {
Context parentContext = request.getContext().getParent();
if (parentContext == null) {
response.setAttr("supplierPartner", "domain", domain);
return;
}
saleOrder = parentContext.asType(SaleOrder.class);
if (saleOrder == null) {
response.setAttr("supplierPartner", "domain", domain);
return;
}
}
String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
}
if (saleOrder.getCompany() != null) {
domain += " AND " + saleOrder.getCompany().getId() + " in (SELECT id FROM self.companySet)";
}
response.setAttr("supplierPartner", "domain", domain);
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class SaleOrderLineController method requestQty.
/**
* Called from sale order line form view, on request qty click. Call {@link
* ReservedQtyService#requestQty(SaleOrderLine)}
*
* @param request
* @param response
*/
public void requestQty(ActionRequest request, ActionResponse response) {
try {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
Product product = saleOrderLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).requestQty(saleOrderLine);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ProjectedStockController method showStockRequestedReservedQuantityOfProduct.
public void showStockRequestedReservedQuantityOfProduct(ActionRequest request, ActionResponse response) {
Map<String, Long> mapId = Beans.get(ProjectedStockService.class).getProductIdCompanyIdStockLocationIdFromContext(request.getContext());
if (mapId == null || mapId.get("productId") == 0L) {
return;
}
Long productId = mapId.get("productId");
Long companyId = mapId.get("companyId");
Long stockLocationId = mapId.get("stockLocationId");
String domain = Beans.get(StockLocationLineService.class).getRequestedReservedQtyForAProduct(productId, companyId, stockLocationId);
Product product = Beans.get(ProductRepository.class).find(mapId.get("productId"));
String title = I18n.get(VIEW_REQUESTED_RESERVED_QTY_TITLE);
title = String.format(title, product.getName());
response.setView(ActionView.define(title).model(StockLocationLine.class.getName()).add("grid", "stock-location-line-grid").add("form", "stock-location-line-form").domain(domain).param("popup", "true").param("popup-save", "false").param("popup.maximized", "true").map());
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveLineController method changeReservedQty.
/**
* Called from stock move line request quantity wizard view. Call {@link
* ReservedQtyService#updateReservedQty(StockMoveLine, BigDecimal)}.
*
* @param request
* @param response
*/
public void changeReservedQty(ActionRequest request, ActionResponse response) {
try {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
BigDecimal newReservedQty = stockMoveLine.getReservedQty();
stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
Product product = stockMoveLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).updateReservedQty(stockMoveLine, newReservedQty);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveLineController method allocateAll.
/**
* Called from stock move form view, on clicking allocateAll button on one stock move line. Call
* {@link ReservedQtyService#allocateAll(StockMoveLine)}.
*
* @param request
* @param response
*/
public void allocateAll(ActionRequest request, ActionResponse response) {
try {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
Product product = stockMoveLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).allocateAll(stockMoveLine);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations