Search in sources :

Example 1 with ProductRepository

use of com.axelor.apps.base.db.repo.ProductRepository 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 2 with ProductRepository

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

the class ProductSupplierServiceImpl method addOnCatalog.

@Transactional(rollbackOn = { Exception.class })
@Override
public Product addOnCatalog(ProductSupplier productSupplier) throws AxelorException {
    ProductRepository productRepo = Beans.get(ProductRepository.class);
    if (productSupplier.getProductCode() == null) {
        throw new AxelorException(productSupplier, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.PRODUCT_SUPPLIER_NO_CODE));
    }
    if (productSupplier.getProductName() == null) {
        throw new AxelorException(productSupplier, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.PRODUCT_SUPPLIER_NO_NAME), productSupplier.getProductCode());
    }
    if (productRepo.findByCode(productSupplier.getProductCode()) != null) {
        throw new AxelorException(productSupplier, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_SUPPLIER_SAME_CODE));
    }
    Product productCreated = createProductFromProductSupplier(productSupplier);
    productSupplier.setProductCreated(productCreated);
    Beans.get(ProductSupplierRepository.class).save(productSupplier);
    return productCreated;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) ProductSupplierRepository(com.axelor.apps.supplierportal.db.repo.ProductSupplierRepository) Transactional(com.google.inject.persist.Transactional)

Aggregations

Product (com.axelor.apps.base.db.Product)2 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)2 ProductSupplierRepository (com.axelor.apps.supplierportal.db.repo.ProductSupplierRepository)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1