use of com.axelor.apps.purchase.db.PurchaseRequest in project axelor-open-suite by axelor.
the class PurchaseRequestServiceImpl method acceptRequest.
@Transactional
@Override
public void acceptRequest(List<PurchaseRequest> purchaseRequests) {
for (PurchaseRequest purchaseRequest : purchaseRequests) {
purchaseRequest.setStatusSelect(3);
purchaseRequestRepo.save(purchaseRequest);
}
}
use of com.axelor.apps.purchase.db.PurchaseRequest in project axelor-open-suite by axelor.
the class PurchaseRequestManagementRepository method copy.
@Override
public PurchaseRequest copy(PurchaseRequest entity, boolean deep) {
PurchaseRequest copy = super.copy(entity, deep);
copy.setStatusSelect(PurchaseRequestRepository.STATUS_DRAFT);
copy.setPurchaseRequestSeq(null);
return copy;
}
use of com.axelor.apps.purchase.db.PurchaseRequest in project axelor-open-suite by axelor.
the class PurchaseRequestServiceImpl method generatePo.
@Transactional(rollbackOn = { Exception.class })
@Override
public List<PurchaseOrder> generatePo(List<PurchaseRequest> purchaseRequests, Boolean groupBySupplier, Boolean groupByProduct) throws AxelorException {
List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>();
Map<String, PurchaseOrder> purchaseOrderMap = new HashMap<>();
for (PurchaseRequest purchaseRequest : purchaseRequests) {
PurchaseOrder purchaseOrder;
String key = groupBySupplier ? getPurchaseOrderGroupBySupplierKey(purchaseRequest) : null;
if (key != null && purchaseOrderMap.containsKey(key)) {
purchaseOrder = purchaseOrderMap.get(key);
} else {
purchaseOrder = createPurchaseOrder(purchaseRequest);
key = key == null ? purchaseRequest.getId().toString() : key;
purchaseOrderMap.put(key, purchaseOrder);
}
if (purchaseOrder == null) {
purchaseOrder = createPurchaseOrder(purchaseRequest);
}
for (PurchaseRequestLine purchaseRequestLine : purchaseRequest.getPurchaseRequestLineList()) {
PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
Product product = purchaseRequestLine.getProduct();
purchaseOrderLine = groupByProduct && purchaseOrder != null ? getPoLineByProduct(product, purchaseOrder) : null;
purchaseOrderLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, purchaseRequestLine.getNewProduct() ? purchaseRequestLine.getProductTitle() : null, null, purchaseRequestLine.getQuantity(), purchaseRequestLine.getUnit());
purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
purchaseOrderLineList.add(purchaseOrderLine);
purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrder);
}
purchaseOrder.getPurchaseOrderLineList().addAll(purchaseOrderLineList);
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrderRepo.save(purchaseOrder);
purchaseRequest.setPurchaseOrder(purchaseOrder);
purchaseRequestRepo.save(purchaseRequest);
}
List<PurchaseOrder> purchaseOrders = purchaseOrderMap.values().stream().collect(Collectors.toList());
return purchaseOrders;
}
use of com.axelor.apps.purchase.db.PurchaseRequest in project axelor-open-suite by axelor.
the class PurchaseRequestServiceImpl method confirmCart.
@Transactional
@Override
public void confirmCart() {
List<PurchaseRequest> purchaseRequests = purchaseRequestRepo.all().filter("self.statusSelect = 1 and self.createdBy = ?1", AuthUtils.getUser()).fetch();
for (PurchaseRequest purchaseRequest : purchaseRequests) {
purchaseRequest.setStatusSelect(2);
purchaseRequestRepo.save(purchaseRequest);
}
}
use of com.axelor.apps.purchase.db.PurchaseRequest in project axelor-open-suite by axelor.
the class PurchaseRequestController method generatePo.
public void generatePo(ActionRequest request, ActionResponse response) {
@SuppressWarnings("unchecked") List<Long> requestIds = (List<Long>) request.getContext().get("_ids");
if (requestIds != null && !requestIds.isEmpty()) {
Boolean groupBySupplier = (Boolean) request.getContext().get("groupBySupplier");
groupBySupplier = groupBySupplier == null ? false : groupBySupplier;
Boolean groupByProduct = (Boolean) request.getContext().get("groupByProduct");
groupByProduct = groupByProduct == null ? false : groupByProduct;
try {
List<PurchaseRequest> purchaseRequests = Beans.get(PurchaseRequestRepository.class).all().filter("self.id in (?1)", requestIds).fetch();
List<String> purchaseRequestSeqs = purchaseRequests.stream().filter(pr -> pr.getSupplierUser() == null).map(PurchaseRequest::getPurchaseRequestSeq).collect(Collectors.toList());
if (purchaseRequestSeqs != null && !purchaseRequestSeqs.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PURCHASE_REQUEST_MISSING_SUPPLIER_USER), purchaseRequestSeqs.toString());
}
response.setCanClose(true);
List<PurchaseOrder> purchaseOrderList = Beans.get(PurchaseRequestService.class).generatePo(purchaseRequests, groupBySupplier, groupByProduct);
ActionViewBuilder actionViewBuilder = ActionView.define(String.format("Purchase Order%s generated", (purchaseOrderList.size() > 1 ? "s" : ""))).model(PurchaseOrder.class.getName()).add("grid", "purchase-order-quotation-grid").add("form", "purchase-order-form").param("search-filters", "purchase-order-filters").context("_showSingle", true).domain(String.format("self.id in (%s)", StringTool.getIdListString(purchaseOrderList)));
response.setView(actionViewBuilder.map());
} catch (AxelorException e) {
response.setFlash(e.getMessage());
}
}
}
Aggregations