use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method preFillOperations.
@Override
@Transactional(rollbackOn = { Exception.class })
public void preFillOperations(ManufOrder manufOrder) throws AxelorException {
BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
if (manufOrder.getProdProcess() == null) {
manufOrder.setProdProcess(billOfMaterial.getProdProcess());
}
ProdProcess prodProcess = manufOrder.getProdProcess();
if (manufOrder.getPlannedStartDateT() == null) {
manufOrder.setPlannedStartDateT(appProductionService.getTodayDateTime().toLocalDateTime());
}
if (prodProcess != null && prodProcess.getProdProcessLineList() != null) {
for (ProdProcessLine prodProcessLine : this._sortProdProcessLineByPriority(prodProcess.getProdProcessLineList())) {
manufOrder.addOperationOrderListItem(operationOrderService.createOperationOrder(manufOrder, prodProcessLine));
}
}
manufOrderRepo.save(manufOrder);
manufOrder.setPlannedEndDateT(manufOrderWorkflowService.computePlannedEndDateT(manufOrder));
manufOrderRepo.save(manufOrder);
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method canMerge.
public boolean canMerge(List<Long> ids) {
List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
// I check if all the status of the manuf order in the list are Draft or
// Planned. If not i can return false
boolean allStatusDraftOrPlanned = manufOrderList.stream().allMatch(x -> x.getStatusSelect().equals(ManufOrderRepository.STATUS_DRAFT) || x.getStatusSelect().equals(ManufOrderRepository.STATUS_PLANNED));
if (!allStatusDraftOrPlanned) {
return false;
}
// I check if all the products are the same. If not i return false
Product product = manufOrderList.get(0).getProduct();
boolean allSameProducts = manufOrderList.stream().allMatch(x -> x.getProduct().equals(product));
if (!allSameProducts) {
return false;
}
// Workshop management must be enabled to do the checking
if (appProductionService.getAppProduction().getManageWorkshop()) {
// Check if one of the workShopStockLocation is null
boolean oneWorkShopIsNull = manufOrderList.stream().anyMatch(x -> x.getWorkshopStockLocation() == null);
if (oneWorkShopIsNull) {
return false;
}
// I check if all the stockLocation are the same. If not i return false
StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
boolean allSameLocation = manufOrderList.stream().allMatch(x -> x.getWorkshopStockLocation() != null && x.getWorkshopStockLocation().equals(stockLocation));
if (!allSameLocation) {
return false;
}
}
// Check if one of the billOfMaterial is null
boolean oneBillOfMaterialIsNull = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial() == null);
if (oneBillOfMaterialIsNull) {
return false;
}
// Check if one of the billOfMaterial has his version equal to 1
boolean oneBillOfMaterialWithFirstVersion = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial().getVersionNumber() == 1);
if (!oneBillOfMaterialWithFirstVersion) {
return false;
}
// I check if all the billOfMaterial are the same. If not i will check
// if all version are compatible, and if not i can return false
BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
boolean allSameOrCompatibleBillOfMaterial = manufOrderList.stream().allMatch(x -> x.getBillOfMaterial().equals(billOfMaterial) || billOfMaterial.equals(x.getBillOfMaterial().getOriginalBillOfMaterial()));
if (!allSameOrCompatibleBillOfMaterial) {
return false;
}
return true;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ProductionOrderSaleOrderServiceImpl method generateManufOrders.
/**
* Loop through bill of materials components to generate manufacturing order for given sale order
* line and all of its sub manuf order needed to get components for parent manufacturing order.
*
* @param productionOrder Initialized production order with no manufacturing order.
* @param billOfMaterial the bill of material of the parent manufacturing order
* @param qtyRequested the quantity requested of the parent manufacturing order.
* @param startDate startDate of creation
* @param saleOrder a sale order
* @return the updated production order with all generated manufacturing orders.
* @throws AxelorException
*/
protected ProductionOrder generateManufOrders(ProductionOrder productionOrder, BillOfMaterial billOfMaterial, BigDecimal qtyRequested, LocalDateTime startDate, SaleOrder saleOrder) throws AxelorException {
List<BillOfMaterial> childBomList = new ArrayList<>();
childBomList.add(billOfMaterial);
// prevent infinite loop
int depth = 0;
while (!childBomList.isEmpty()) {
if (depth >= 100) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHILD_BOM_TOO_MANY_ITERATION));
}
List<BillOfMaterial> tempChildBomList = new ArrayList<>();
for (BillOfMaterial childBom : childBomList) {
productionOrder = productionOrderService.addManufOrder(productionOrder, childBom.getProduct(), childBom, qtyRequested.multiply(childBom.getQty()), startDate, null, saleOrder, ManufOrderService.ORIGIN_TYPE_SALE_ORDER);
tempChildBomList.addAll(childBom.getBillOfMaterialSet().stream().filter(BillOfMaterial::getDefineSubBillOfMaterial).collect(Collectors.toList()));
}
childBomList.clear();
childBomList.addAll(tempChildBomList);
tempChildBomList.clear();
depth++;
}
return productionOrder;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ProductionOrderSaleOrderServiceImpl method generateManufOrders.
@Override
public ProductionOrder generateManufOrders(ProductionOrder productionOrder, SaleOrderLine saleOrderLine) throws AxelorException {
Product product = saleOrderLine.getProduct();
if (saleOrderLine.getSaleSupplySelect() == ProductRepository.SALE_SUPPLY_PRODUCE && product != null && product.getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_STORABLE)) {
BillOfMaterial billOfMaterial = saleOrderLine.getBillOfMaterial();
if (billOfMaterial == null) {
billOfMaterial = product.getDefaultBillOfMaterial();
}
if (billOfMaterial == null && product.getParentProduct() != null) {
billOfMaterial = product.getParentProduct().getDefaultBillOfMaterial();
}
if (billOfMaterial == null) {
throw new AxelorException(saleOrderLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_SALES_ORDER_NO_BOM), product.getName(), product.getCode());
}
if (billOfMaterial.getProdProcess() == null) {
return null;
}
Unit unit = saleOrderLine.getProduct().getUnit();
BigDecimal qty = saleOrderLine.getQty();
if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
}
return generateManufOrders(productionOrder, billOfMaterial, qty, LocalDateTime.now(), saleOrderLine.getSaleOrder());
}
return null;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ProductionOrderWizardServiceImpl method validate.
@Override
@SuppressWarnings("unchecked")
public Long validate(Context context) throws AxelorException {
Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial");
BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue());
BigDecimal qty = new BigDecimal((String) context.get("qty"));
Product product = null;
if (context.get("product") != null) {
Map<String, Object> productContext = (Map<String, Object>) context.get("product");
product = productRepo.find(((Integer) productContext.get("id")).longValue());
} else {
product = billOfMaterial.getProduct();
}
ZonedDateTime startDateT;
if (context.containsKey("_startDate") && context.get("_startDate") != null) {
startDateT = ZonedDateTime.parse((CharSequence) context.get("_startDate"), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
} else {
startDateT = appProductionService.getTodayDateTime();
}
ProductionOrder productionOrder = productionOrderService.generateProductionOrder(product, billOfMaterial, qty, startDateT.toLocalDateTime());
if (productionOrder != null) {
return productionOrder.getId();
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_2));
}
}
Aggregations