use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method createManufOrder.
@Override
public ManufOrder createManufOrder(Product product, BigDecimal qty, int priority, boolean isToInvoice, Company company, BillOfMaterial billOfMaterial, LocalDateTime plannedStartDateT, LocalDateTime plannedEndDateT) throws AxelorException {
logger.debug("Création d'un OF {}", priority);
ProdProcess prodProcess = billOfMaterial.getProdProcess();
ManufOrder manufOrder = new ManufOrder(qty, company, null, priority, this.isManagedConsumedProduct(billOfMaterial), billOfMaterial, product, prodProcess, plannedStartDateT, plannedEndDateT, ManufOrderRepository.STATUS_DRAFT, prodProcess.getOutsourcing());
manufOrder = manufOrderRepo.save(manufOrder);
if (appProductionService.getAppProduction().getManageWorkshop()) {
manufOrder.setWorkshopStockLocation(billOfMaterial.getWorkshopStockLocation());
}
if (prodProcess != null && prodProcess.getProdProcessLineList() != null) {
for (ProdProcessLine prodProcessLine : this._sortProdProcessLineByPriority(prodProcess.getProdProcessLineList())) {
manufOrder.addOperationOrderListItem(operationOrderService.createOperationOrder(manufOrder, prodProcessLine));
}
}
return manufOrder;
}
use of com.axelor.apps.production.db.ManufOrder 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);
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method generateManufOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public ManufOrder generateManufOrder(Product product, BigDecimal qtyRequested, int priority, boolean isToInvoice, BillOfMaterial billOfMaterial, LocalDateTime plannedStartDateT, LocalDateTime plannedEndDateT, int originType) throws AxelorException {
if (billOfMaterial == null) {
billOfMaterial = this.getBillOfMaterial(product);
}
Company company = billOfMaterial.getCompany();
BigDecimal qty = qtyRequested.divide(billOfMaterial.getQty(), appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
ManufOrder manufOrder = this.createManufOrder(product, qty, priority, IS_TO_INVOICE, company, billOfMaterial, plannedStartDateT, plannedEndDateT);
if (originType == ORIGIN_TYPE_SALE_ORDER && appProductionService.getAppProduction().getAutoPlanManufOrderFromSO() || originType == ORIGIN_TYPE_MRP || originType == ORIGIN_TYPE_OTHER) {
manufOrder = manufOrderWorkflowService.plan(manufOrder);
}
return manufOrderRepo.save(manufOrder);
}
use of com.axelor.apps.production.db.ManufOrder 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.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method createNewProducedStockMoveLineList.
/**
* Clear the produced list and create a new one with the right quantity.
*
* @param manufOrder
* @param qtyToUpdate
*/
public void createNewProducedStockMoveLineList(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
Optional<StockMove> stockMoveOpt = getPlannedStockMove(manufOrder.getOutStockMoveList());
if (!stockMoveOpt.isPresent()) {
return;
}
StockMove stockMove = stockMoveOpt.get();
stockMoveService.cancel(stockMove);
// clear all lists
manufOrder.getProducedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
stockMove.clearStockMoveLineList();
// create a new list
for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
BigDecimal qty = getFractionQty(manufOrder, prodProduct, qtyToUpdate);
BigDecimal productCostPrice = prodProduct.getProduct() != null ? (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", manufOrder.getCompany()) : BigDecimal.ZERO;
_createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_OUT_PRODUCTIONS, qty, productCostPrice);
// Update produced StockMoveLineList with created stock move lines
stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !manufOrder.getProducedStockMoveLineList().contains(stockMoveLine1)).forEach(manufOrder::addProducedStockMoveLineListItem);
}
stockMoveService.plan(stockMove);
}
Aggregations