use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ConfiguratorServiceProductionImpl method generate.
/**
* In this implementation, we also create a bill of materials.
*
* @param configurator
* @param jsonAttributes
* @param jsonIndicators
* @throws AxelorException
*/
@Override
@Transactional(rollbackOn = { Exception.class })
public void generate(Configurator configurator, JsonContext jsonAttributes, JsonContext jsonIndicators) throws AxelorException {
super.generate(configurator, jsonAttributes, jsonIndicators);
ConfiguratorBOM configuratorBOM = configurator.getConfiguratorCreator().getConfiguratorBom();
if (configuratorBOM != null) {
Product generatedProduct = configurator.getProduct();
Beans.get(ConfiguratorBomService.class).generateBillOfMaterial(configuratorBOM, jsonAttributes, 0, generatedProduct).ifPresent(generatedProduct::setDefaultBillOfMaterial);
}
}
use of com.axelor.apps.base.db.Product 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.Product in project axelor-open-suite by axelor.
the class MrpForecastProductionServiceImpl method generateMrpForecast.
@Override
public void generateMrpForecast(Period period, List<LinkedHashMap<String, Object>> mrpForecastList, StockLocation stockLocation, int technicalOrigin) {
LocalDate forecastDate = period.getToDate();
for (LinkedHashMap<String, Object> mrpForecastItem : mrpForecastList) {
Long id = mrpForecastItem.get("id") != null ? Long.parseLong(mrpForecastItem.get("id").toString()) : null;
BigDecimal qty = new BigDecimal(mrpForecastItem.get("qty").toString());
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> productMap = (LinkedHashMap<String, Object>) mrpForecastItem.get("product");
Product product = productRepo.find(Long.parseLong(productMap.get("id").toString()));
if (id != null && qty.compareTo(BigDecimal.ZERO) == 0) {
this.RemoveMrpForecast(id);
} else if (qty.compareTo(BigDecimal.ZERO) != 0) {
this.createMrpForecast(id, forecastDate, product, stockLocation, qty, technicalOrigin);
}
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class MrpLineServiceProductionImpl method generateManufacturingProposal.
@Transactional(rollbackOn = { Exception.class })
protected void generateManufacturingProposal(MrpLine mrpLine) throws AxelorException {
Product product = mrpLine.getProduct();
ManufOrder manufOrder = manufOrderService.generateManufOrder(product, mrpLine.getQty(), ManufOrderService.DEFAULT_PRIORITY, ManufOrderService.IS_TO_INVOICE, null, mrpLine.getMaturityDate().atStartOfDay(), null, ManufOrderServiceImpl.ORIGIN_TYPE_MRP);
// correct day
linkToOrder(mrpLine, manufOrder);
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ProductionProductStockLocationServiceImpl method computeIndicators.
@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
Map<String, Object> map = super.computeIndicators(productId, companyId, stockLocationId);
Product product = productRepository.find(productId);
Company company = companyRepository.find(companyId);
StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
int scale = appBaseService.getNbDecimalDigitForQty();
BigDecimal consumeManufOrderQty = this.getConsumeManufOrderQty(product, company, stockLocation).setScale(scale, RoundingMode.HALF_UP);
BigDecimal availableQty = (BigDecimal) map.getOrDefault("$availableQty", BigDecimal.ZERO.setScale(scale, RoundingMode.HALF_UP));
map.put("$buildingQty", this.getBuildingQty(product, company, stockLocation).setScale(scale, RoundingMode.HALF_UP));
map.put("$consumeManufOrderQty", consumeManufOrderQty);
map.put("$missingManufOrderQty", BigDecimal.ZERO.max(consumeManufOrderQty.subtract(availableQty)).setScale(scale, RoundingMode.HALF_UP));
return map;
}
Aggregations