Search in sources :

Example 1 with ProductVariant

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

the class ProductServiceImpl method generateProductVariants.

@Override
@Transactional
public void generateProductVariants(Product productModel) throws AxelorException {
    List<ProductVariant> productVariantList = this.getProductVariantList(productModel.getProductVariantConfig());
    int seq = 1;
    List<Product> productVariantsList = productRepo.all().filter("self.parentProduct = ?1", productModel).fetch();
    if (productVariantsList != null && !productVariantsList.isEmpty()) {
        Integer lastSeq = 0;
        for (Product product : productVariantsList) {
            Integer productSeq = Integer.parseInt(StringUtils.substringAfterLast(product.getCode(), "-"));
            if (productSeq.compareTo(lastSeq) > 0) {
                lastSeq = productSeq;
            }
        }
        seq = lastSeq + 1;
    }
    for (ProductVariant productVariant : productVariantList) {
        productVariantRepo.save(productVariant);
        productRepo.save(this.createProduct(productModel, productVariant, seq++));
    }
}
Also used : Product(com.axelor.apps.base.db.Product) ProductVariant(com.axelor.apps.base.db.ProductVariant) Transactional(com.google.inject.persist.Transactional)

Example 2 with ProductVariant

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

the class ProductVariantService method containsProductVariantValue.

private boolean containsProductVariantValue(Product product, ProductVariantValue productVariantValue) {
    ProductVariant productVariantFind = product.getProductVariant();
    ProductVariantValue productVariantValue1 = productVariantFind.getProductVariantValue1();
    ProductVariantValue productVariantValue2 = productVariantFind.getProductVariantValue2();
    ProductVariantValue productVariantValue3 = productVariantFind.getProductVariantValue3();
    ProductVariantValue productVariantValue4 = productVariantFind.getProductVariantValue4();
    if ((productVariantValue1 != null && productVariantValue1.getCode().equals(productVariantValue.getCode()) && productVariantValue1.getProductVariantAttr().getCode().equals(productVariantValue.getProductVariantAttr().getCode())) || (productVariantValue2 != null && productVariantValue2.getCode().equals(productVariantValue.getCode()) && productVariantValue2.getProductVariantAttr().getCode().equals(productVariantValue.getProductVariantAttr().getCode())) || (productVariantValue3 != null && productVariantValue3.getCode().equals(productVariantValue.getCode()) && productVariantValue3.getProductVariantAttr().getCode().equals(productVariantValue.getProductVariantAttr().getCode())) || (productVariantValue4 != null && productVariantValue4.getCode().equals(productVariantValue.getCode()) && productVariantValue4.getProductVariantAttr().getCode().equals(productVariantValue.getProductVariantAttr().getCode()))) {
        return true;
    }
    return false;
}
Also used : ProductVariantValue(com.axelor.apps.base.db.ProductVariantValue) ProductVariant(com.axelor.apps.base.db.ProductVariant)

Example 3 with ProductVariant

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

the class ProductVariantService method createProductVariant.

public ProductVariant createProductVariant(ProductVariantAttr productVariantAttr1, ProductVariantAttr productVariantAttr2, ProductVariantAttr productVariantAttr3, ProductVariantAttr productVariantAttr4, ProductVariantValue productVariantValue1, ProductVariantValue productVariantValue2, ProductVariantValue productVariantValue3, ProductVariantValue productVariantValue4, boolean usedForStock) {
    ProductVariant productVariant = new ProductVariant();
    productVariant.setProductVariantAttr1(productVariantAttr1);
    productVariant.setProductVariantAttr2(productVariantAttr2);
    productVariant.setProductVariantAttr3(productVariantAttr3);
    productVariant.setProductVariantAttr4(productVariantAttr4);
    productVariant.setProductVariantValue1(productVariantValue1);
    productVariant.setProductVariantValue2(productVariantValue2);
    productVariant.setProductVariantValue3(productVariantValue3);
    productVariant.setProductVariantValue4(productVariantValue4);
    productVariant.setUsedForStock(usedForStock);
    return productVariant;
}
Also used : ProductVariant(com.axelor.apps.base.db.ProductVariant)

Aggregations

ProductVariant (com.axelor.apps.base.db.ProductVariant)3 Product (com.axelor.apps.base.db.Product)1 ProductVariantValue (com.axelor.apps.base.db.ProductVariantValue)1 Transactional (com.google.inject.persist.Transactional)1