Search in sources :

Example 16 with Unit

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

the class ContractLineServiceImpl method fill.

@Override
public ContractLine fill(ContractLine contractLine, Product product) throws AxelorException {
    Preconditions.checkNotNull(product, I18n.get(IExceptionMessage.CONTRACT_EMPTY_PRODUCT));
    Company company = contractLine.getContractVersion() != null ? contractLine.getContractVersion().getContract() != null ? contractLine.getContractVersion().getContract().getCompany() : null : null;
    contractLine.setProductName((String) productCompanyService.get(product, "name", company));
    Unit unit = (Unit) productCompanyService.get(product, "salesUnit", company);
    if (unit != null) {
        contractLine.setUnit(unit);
    } else {
        contractLine.setUnit((Unit) productCompanyService.get(product, "unit", company));
    }
    contractLine.setPrice((BigDecimal) productCompanyService.get(product, "salePrice", company));
    contractLine.setDescription((String) productCompanyService.get(product, "description", company));
    return contractLine;
}
Also used : Company(com.axelor.apps.base.db.Company) Unit(com.axelor.apps.base.db.Unit)

Example 17 with Unit

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

the class SaleOrderLineController method checkStocks.

public void checkStocks(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    SaleOrder saleOrder = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getSaleOrder(request.getContext());
    if (saleOrder.getStockLocation() == null) {
        return;
    }
    try {
        if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_FROM_STOCK) {
            return;
        }
        // Use the unit to get the right quantity
        Unit unit = null;
        if (saleOrderLine.getProduct() != null)
            unit = saleOrderLine.getProduct().getUnit();
        BigDecimal qty = saleOrderLine.getQty();
        if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
        }
        Beans.get(StockLocationLineService.class).checkIfEnoughStock(saleOrder.getStockLocation(), saleOrderLine.getProduct(), qty);
    } catch (Exception e) {
        response.setAlert(e.getLocalizedMessage());
    }
}
Also used : StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) SaleOrderLineServiceSupplyChainImpl(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChainImpl) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 18 with Unit

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

the class ProjectTaskBusinessProjectServiceImpl method computeDefaultInformation.

@Override
public ProjectTask computeDefaultInformation(ProjectTask projectTask) throws AxelorException {
    Product product = projectTask.getProduct();
    if (product != null) {
        projectTask.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
        if (projectTask.getUnitPrice() == null || projectTask.getUnitPrice().compareTo(BigDecimal.ZERO) == 0) {
            projectTask.setUnitPrice(this.computeUnitPrice(projectTask));
        }
    } else {
        ProjectTaskCategory projectTaskCategory = projectTask.getProjectTaskCategory();
        if (projectTaskCategory == null) {
            return projectTask;
        }
        projectTask.setInvoicingType(projectTaskCategory.getDefaultInvoicingType());
        projectTask.setProduct(projectTaskCategory.getDefaultProduct());
        product = projectTask.getProduct();
        if (product == null) {
            return projectTask;
        }
        projectTask.setUnitPrice(this.computeUnitPrice(projectTask));
    }
    Company company = projectTask.getProject() != null ? projectTask.getProject().getCompany() : null;
    Unit salesUnit = (Unit) productCompanyService.get(product, "salesUnit", company);
    projectTask.setUnit(salesUnit != null ? salesUnit : (Unit) productCompanyService.get(product, "unit", company));
    projectTask.setCurrency((Currency) productCompanyService.get(product, "saleCurrency", company));
    projectTask.setQuantity(projectTask.getBudgetedTime());
    projectTask.setQuantity(projectTask.getBudgetedTime() == null || projectTask.getBudgetedTime().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : projectTask.getBudgetedTime());
    projectTask = this.updateDiscount(projectTask);
    projectTask = this.compute(projectTask);
    return projectTask;
}
Also used : ProjectTaskCategory(com.axelor.apps.project.db.ProjectTaskCategory) Company(com.axelor.apps.base.db.Company) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit)

Example 19 with Unit

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

the class ConfiguratorBomServiceImpl method generateBillOfMaterial.

@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<BillOfMaterial> generateBillOfMaterial(ConfiguratorBOM configuratorBOM, JsonContext attributes, int level, Product generatedProduct) throws AxelorException {
    level++;
    if (level > MAX_LEVEL) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_TOO_MANY_CALLS));
    }
    String name;
    Product product;
    BigDecimal qty;
    Unit unit;
    ProdProcess prodProcess;
    if (!checkConditions(configuratorBOM, attributes)) {
        return Optional.empty();
    }
    if (configuratorBOM.getDefNameAsFormula()) {
        name = (String) configuratorService.computeFormula(configuratorBOM.getNameFormula(), attributes);
    } else {
        name = configuratorBOM.getName();
    }
    if (configuratorBOM.getDefProductFromConfigurator()) {
        if (generatedProduct == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_GENERATED_PRODUCT_NULL));
        }
        product = generatedProduct;
    } else if (configuratorBOM.getDefProductAsFormula()) {
        product = (Product) configuratorService.computeFormula(configuratorBOM.getProductFormula(), attributes);
        if (product == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FORMULA_PRODUCT_NULL));
        }
        product = Beans.get(ProductRepository.class).find(product.getId());
    } else {
        if (configuratorBOM.getProduct() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FILLED_PRODUCT_NULL));
        }
        product = configuratorBOM.getProduct();
    }
    if (configuratorBOM.getDefQtyAsFormula()) {
        qty = new BigDecimal(configuratorService.computeFormula(configuratorBOM.getQtyFormula(), attributes).toString());
    } else {
        qty = configuratorBOM.getQty();
    }
    if (configuratorBOM.getDefUnitAsFormula()) {
        unit = (Unit) configuratorService.computeFormula(configuratorBOM.getUnitFormula(), attributes);
        if (unit != null) {
            unit = Beans.get(UnitRepository.class).find(unit.getId());
        }
    } else {
        unit = configuratorBOM.getUnit();
    }
    if (configuratorBOM.getDefProdProcessAsFormula()) {
        prodProcess = (ProdProcess) configuratorService.computeFormula(configuratorBOM.getProdProcessFormula(), attributes);
        if (prodProcess != null) {
            prodProcess = Beans.get(ProdProcessRepository.class).find(prodProcess.getId());
        }
    } else if (configuratorBOM.getDefProdProcessAsConfigurator()) {
        prodProcess = confProdProcessService.generateProdProcessService(configuratorBOM.getConfiguratorProdProcess(), attributes, product);
    } else {
        prodProcess = configuratorBOM.getProdProcess();
    }
    BillOfMaterial billOfMaterial = new BillOfMaterial();
    billOfMaterial.setCompany(configuratorBOM.getCompany());
    billOfMaterial.setName(name);
    billOfMaterial.setProduct(product);
    billOfMaterial.setQty(qty);
    billOfMaterial.setUnit(unit);
    billOfMaterial.setProdProcess(prodProcess);
    billOfMaterial.setStatusSelect(configuratorBOM.getStatusSelect());
    billOfMaterial.setDefineSubBillOfMaterial(configuratorBOM.getDefineSubBillOfMaterial());
    if (configuratorBOM.getConfiguratorBomList() != null) {
        for (ConfiguratorBOM confBomChild : configuratorBOM.getConfiguratorBomList()) {
            generateBillOfMaterial(confBomChild, attributes, level, generatedProduct).ifPresent(billOfMaterial::addBillOfMaterialSetItem);
        }
    }
    billOfMaterial = billOfMaterialRepository.save(billOfMaterial);
    configuratorBOM.setBillOfMaterialId(billOfMaterial.getId());
    configuratorBOMRepo.save(configuratorBOM);
    return Optional.of(billOfMaterial);
}
Also used : AxelorException(com.axelor.exception.AxelorException) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) ConfiguratorBOM(com.axelor.apps.production.db.ConfiguratorBOM) ProdProcess(com.axelor.apps.production.db.ProdProcess) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 20 with Unit

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

the class MrpForecastProductionServiceImpl method createMrpForecast.

@Transactional
public void createMrpForecast(Long id, LocalDate forecastDate, Product product, StockLocation stockLocation, BigDecimal qty, int technicalOrigin) {
    Unit unit = product.getSalesUnit() != null ? product.getSalesUnit() : product.getUnit();
    MrpForecast mrpForecast = id != null ? mrpForecastRepo.find(id) : new MrpForecast();
    if (id != null && mrpForecast.getForecastDate().equals(forecastDate) && mrpForecast.getStockLocation().equals(stockLocation) && mrpForecast.getQty().compareTo(qty) == 0 && mrpForecast.getUnit().equals(unit)) {
        return;
    }
    mrpForecast.setForecastDate(forecastDate);
    mrpForecast.setProduct(product);
    mrpForecast.setStockLocation(stockLocation);
    mrpForecast.setQty(qty);
    mrpForecast.setTechnicalOrigin(technicalOrigin);
    mrpForecast.setUnit(unit);
    mrpForecast.setStatusSelect(MrpForecastRepository.STATUS_DRAFT);
    mrpForecastRepo.save(mrpForecast);
}
Also used : Unit(com.axelor.apps.base.db.Unit) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Transactional(com.google.inject.persist.Transactional)

Aggregations

Unit (com.axelor.apps.base.db.Unit)45 BigDecimal (java.math.BigDecimal)38 Product (com.axelor.apps.base.db.Product)19 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)11 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)9 Company (com.axelor.apps.base.db.Company)8 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)8 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 StockLocation (com.axelor.apps.stock.db.StockLocation)6 StockMove (com.axelor.apps.stock.db.StockMove)6 LocalDate (java.time.LocalDate)6 List (java.util.List)6 ProdProduct (com.axelor.apps.production.db.ProdProduct)5 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)5 ArrayList (java.util.ArrayList)5 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)4