use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class BillOfMaterialServiceImpl method getLatestBillOfMaterialVersion.
public int getLatestBillOfMaterialVersion(BillOfMaterial billOfMaterial, int latestVersion, boolean deep) {
List<BillOfMaterial> billOfMaterialSet;
BillOfMaterial up = billOfMaterial;
Long previousId = 0L;
do {
billOfMaterialSet = billOfMaterialRepo.all().filter("self.originalBillOfMaterial = :origin AND self.id != :id").bind("origin", up).bind("id", previousId).order("-versionNumber").fetch();
if (!billOfMaterialSet.isEmpty()) {
latestVersion = (billOfMaterialSet.get(0).getVersionNumber() > latestVersion) ? billOfMaterialSet.get(0).getVersionNumber() : latestVersion;
for (BillOfMaterial billOfMaterialIterator : billOfMaterialSet) {
int search = this.getLatestBillOfMaterialVersion(billOfMaterialIterator, latestVersion, false);
latestVersion = (search > latestVersion) ? search : latestVersion;
}
}
previousId = up.getId();
up = up.getOriginalBillOfMaterial();
} while (up != null && deep);
return latestVersion;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class BillOfMaterialManagementRepository method copy.
@Override
public BillOfMaterial copy(BillOfMaterial entity, boolean deep) {
BillOfMaterial copy = super.copy(entity, deep);
copy.setStatusSelect(STATUS_DRAFT);
copy.setVersionNumber(1);
copy.setOriginalBillOfMaterial(null);
copy.setCostPrice(BigDecimal.ZERO);
copy.clearCostSheetList();
copy.clearBillOfMaterialSet();
Set<BillOfMaterial> billOfMaterials = entity.getBillOfMaterialSet();
if (billOfMaterials != null && !billOfMaterials.isEmpty()) {
billOfMaterials.forEach(bom -> copy.addBillOfMaterialSetItem(copy(bom, deep)));
}
return copy;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ImportBillOfMaterial method computeCostPrice.
@Transactional(rollbackOn = { Exception.class })
public Object computeCostPrice(Object bean, Map values) throws AxelorException {
if (bean == null) {
return bean;
}
assert bean instanceof BillOfMaterial;
BillOfMaterial bom = (BillOfMaterial) bean;
bom = bomRepo.save(bom);
if (bom.getDefineSubBillOfMaterial()) {
costSheetService.computeCostPrice(bom, CostSheetService.ORIGIN_BILL_OF_MATERIAL, null);
billOfMaterialService.updateProductCostPrice(bom);
}
return bom;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method getToConsumeSubBomList.
public List<Pair<BillOfMaterial, BigDecimal>> getToConsumeSubBomList(BillOfMaterial billOfMaterial, ManufOrder mo, List<Product> productList) {
List<Pair<BillOfMaterial, BigDecimal>> bomList = new ArrayList<>();
for (BillOfMaterial bom : billOfMaterial.getBillOfMaterialSet()) {
Product product = bom.getProduct();
if (productList != null && !productList.contains(product)) {
continue;
}
BigDecimal qtyReq = computeToConsumeProdProductLineQuantity(mo.getBillOfMaterial().getQty(), mo.getQty(), bom.getQty());
if (bom.getDefineSubBillOfMaterial()) {
if (bom.getProdProcess() != null) {
bomList.add(Pair.of(bom, qtyReq));
}
} else {
if ((product.getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || product.getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT) && product.getDefaultBillOfMaterial() != null && product.getDefaultBillOfMaterial().getProdProcess() != null) {
bomList.add(Pair.of(product.getDefaultBillOfMaterial(), qtyReq));
}
}
}
return bomList;
}
use of com.axelor.apps.production.db.BillOfMaterial in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method merge.
@Transactional(rollbackOn = { Exception.class })
public void merge(List<Long> ids) throws AxelorException {
if (!canMerge(ids)) {
throw new AxelorException(ManufOrder.class, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.MANUF_ORDER_NO_GENERATION));
}
List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
/* Init all the necessary values to create the new Manuf Order */
Product product = manufOrderList.get(0).getProduct();
StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
Company company = manufOrderList.get(0).getCompany();
BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
int priority = manufOrderList.stream().mapToInt(ManufOrder::getPrioritySelect).max().orElse(2);
Unit unit = billOfMaterial.getUnit();
BigDecimal qty = BigDecimal.ZERO;
String note = "";
ManufOrder mergedManufOrder = new ManufOrder();
for (ManufOrder manufOrder : manufOrderList) {
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_MERGED);
manufOrder.setManufOrderMergeResult(mergedManufOrder);
for (ProductionOrder productionOrder : manufOrder.getProductionOrderSet()) {
mergedManufOrder.addProductionOrderSetItem(productionOrder);
}
for (SaleOrder saleOrder : manufOrder.getSaleOrderSet()) {
mergedManufOrder.addSaleOrderSetItem(saleOrder);
}
/*
* If unit are the same, then add the qty If not, convert the unit and get the converted qty
*/
if (manufOrder.getUnit().equals(unit)) {
qty = qty.add(manufOrder.getQty());
} else {
BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(manufOrder.getUnit(), unit, manufOrder.getQty(), appBaseService.getNbDecimalDigitForQty(), null);
qty = qty.add(qtyConverted);
}
if (manufOrder.getNote() != null && !manufOrder.getNote().equals("")) {
note += manufOrder.getManufOrderSeq() + " : " + manufOrder.getNote() + "\n";
}
}
Optional<LocalDateTime> minDate = manufOrderList.stream().filter(mo -> mo.getPlannedStartDateT() != null).map(ManufOrder::getPlannedStartDateT).min(LocalDateTime::compareTo);
minDate.ifPresent(mergedManufOrder::setPlannedStartDateT);
/* Update the created manuf order */
mergedManufOrder.setStatusSelect(ManufOrderRepository.STATUS_DRAFT);
mergedManufOrder.setProduct(product);
mergedManufOrder.setUnit(unit);
mergedManufOrder.setWorkshopStockLocation(stockLocation);
mergedManufOrder.setQty(qty);
mergedManufOrder.setBillOfMaterial(billOfMaterial);
mergedManufOrder.setCompany(company);
mergedManufOrder.setPrioritySelect(priority);
mergedManufOrder.setProdProcess(billOfMaterial.getProdProcess());
mergedManufOrder.setNote(note);
/*
* Check the config to see if you directly plan the created manuf order or just prefill the
* operations
*/
if (appProductionService.isApp("production") && appProductionService.getAppProduction().getIsManufOrderPlannedAfterMerge()) {
manufOrderWorkflowService.plan(mergedManufOrder);
} else {
preFillOperations(mergedManufOrder);
}
manufOrderRepo.save(mergedManufOrder);
}
Aggregations