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;
}
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());
}
}
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;
}
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);
}
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);
}
Aggregations