Search in sources :

Example 66 with Product

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);
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) BlockingService(com.axelor.apps.base.service.BlockingService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 67 with Product

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 68 with Product

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());
}
Also used : StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 69 with Product

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 70 with Product

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16