Search in sources :

Example 1 with PurchaseRequest

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);
    }
}
Also used : PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest) Transactional(com.google.inject.persist.Transactional)

Example 2 with 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;
}
Also used : PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest)

Example 3 with PurchaseRequest

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;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PurchaseRequestLine(com.axelor.apps.purchase.db.PurchaseRequestLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest) Transactional(com.google.inject.persist.Transactional)

Example 4 with PurchaseRequest

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);
    }
}
Also used : PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest) Transactional(com.google.inject.persist.Transactional)

Example 5 with 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());
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) PurchaseRequestService(com.axelor.apps.purchase.service.PurchaseRequestService) PurchaseRequestRepository(com.axelor.apps.purchase.db.repo.PurchaseRequestRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) List(java.util.List) PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest)

Aggregations

PurchaseRequest (com.axelor.apps.purchase.db.PurchaseRequest)5 Transactional (com.google.inject.persist.Transactional)3 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)2 Product (com.axelor.apps.base.db.Product)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 PurchaseRequestLine (com.axelor.apps.purchase.db.PurchaseRequestLine)1 PurchaseRequestRepository (com.axelor.apps.purchase.db.repo.PurchaseRequestRepository)1 PurchaseRequestService (com.axelor.apps.purchase.service.PurchaseRequestService)1 AxelorException (com.axelor.exception.AxelorException)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1