Search in sources :

Example 61 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ConfiguratorServiceImpl method generateProduct.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateProduct(Configurator configurator, JsonContext jsonAttributes, JsonContext jsonIndicators) throws AxelorException {
    cleanIndicators(jsonIndicators);
    Mapper mapper = Mapper.of(Product.class);
    Product product = new Product();
    for (String key : jsonIndicators.keySet()) {
        mapper.set(product, key, jsonIndicators.get(key));
    }
    fixRelationalFields(product);
    fetchManyToManyFields(product);
    fillOneToManyFields(configurator, product, jsonAttributes);
    if (product.getProductTypeSelect() == null) {
        product.setProductTypeSelect(ProductRepository.PRODUCT_TYPE_STORABLE);
    }
    if (product.getCode() == null) {
        throw new AxelorException(configurator, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CONFIGURATOR_PRODUCT_MISSING_CODE));
    }
    if (product.getName() == null) {
        throw new AxelorException(configurator, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CONFIGURATOR_PRODUCT_MISSING_NAME));
    }
    configurator.setProduct(product);
    product.setConfigurator(configurator);
    Beans.get(ProductRepository.class).save(product);
}
Also used : Mapper(com.axelor.db.mapper.Mapper) AxelorException(com.axelor.exception.AxelorException) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) Transactional(com.google.inject.persist.Transactional)

Example 62 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class PartnerSaleServiceImpl method getProductBoughtByCustomer.

public List<Product> getProductBoughtByCustomer(Partner customer) {
    String domain = "self.id in (SELECT line.product" + " FROM SaleOrderLine line join SaleOrder sale on line.saleOrder = sale.id" + " WHERE sale.statusSelect IN (" + SaleOrderRepository.STATUS_ORDER_CONFIRMED + ", " + SaleOrderRepository.STATUS_ORDER_COMPLETED + ")" + " AND sale.clientPartner = " + customer.getId() + ")";
    ProductRepository productRepo = Beans.get(ProductRepository.class);
    List<Product> productList = productRepo.all().filter(domain).fetch();
    return productList;
}
Also used : ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product)

Example 63 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class SaleOrderLineController method cancelReservation.

/**
 * Called from sale order line form view, on request qty click. Call {@link
 * ReservedQtyService#cancelReservation(SaleOrderLine)}
 *
 * @param request
 * @param response
 */
public void cancelReservation(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).cancelReservation(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 64 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class SaleOrderLineController method changeReservedQty.

/**
 * Called from sale order line request quantity wizard view. Call {@link
 * ReservedQtyService#updateReservedQty(SaleOrderLine, BigDecimal)}.
 *
 * @param request
 * @param response
 */
public void changeReservedQty(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    BigDecimal newReservedQty = saleOrderLine.getReservedQty();
    try {
        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).updateReservedQty(saleOrderLine, newReservedQty);
    } 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) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 65 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class SaleOrderLineController method allocateAll.

/**
 * Called from sale order form view, on clicking allocateAll button on one sale order line. Call
 * {@link ReservedQtyService#allocateAll(SaleOrderLine)}.
 *
 * @param request
 * @param response
 */
public void allocateAll(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).allocateAll(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)

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