Search in sources :

Example 66 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getPurchaseOrder.

public PurchaseOrder getPurchaseOrder(Context context) {
    Context parentContext = context.getParent();
    PurchaseOrder purchaseOrder = null;
    if (parentContext != null && parentContext.getContextClass() == PurchaseOrder.class) {
        purchaseOrder = parentContext.asType(PurchaseOrder.class);
        if (!parentContext.getContextClass().toString().equals(PurchaseOrder.class.toString())) {
            PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
            purchaseOrder = purchaseOrderLine.getPurchaseOrder();
        }
    } else {
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    }
    return purchaseOrder;
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 67 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getTaxEquiv.

public void getTaxEquiv(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = getPurchaseOrder(context);
    response.setValue("taxEquiv", null);
    if (purchaseOrder == null || purchaseOrderLine == null || purchaseOrder.getSupplierPartner() == null || purchaseOrderLine.getTaxLine() == null)
        return;
    response.setValue("taxEquiv", Beans.get(FiscalPositionService.class).getTaxEquiv(purchaseOrder.getSupplierPartner().getFiscalPosition(), purchaseOrderLine.getTaxLine().getTax()));
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 68 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method mergePurchaseOrders.

@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder mergePurchaseOrders(List<PurchaseOrder> purchaseOrderList, Currency currency, Partner supplierPartner, Company company, Partner contactPartner, PriceList priceList, TradingName tradingName) throws AxelorException {
    String numSeq = "";
    String externalRef = "";
    for (PurchaseOrder purchaseOrderLocal : purchaseOrderList) {
        if (!numSeq.isEmpty()) {
            numSeq += "-";
        }
        numSeq += purchaseOrderLocal.getPurchaseOrderSeq();
        if (!externalRef.isEmpty()) {
            externalRef += "|";
        }
        if (purchaseOrderLocal.getExternalReference() != null) {
            externalRef += purchaseOrderLocal.getExternalReference();
        }
    }
    PurchaseOrder purchaseOrderMerged = this.createPurchaseOrder(AuthUtils.getUser(), company, contactPartner, currency, null, numSeq, externalRef, appPurchaseService.getTodayDate(company), priceList, supplierPartner, tradingName);
    this.attachToNewPurchaseOrder(purchaseOrderList, purchaseOrderMerged);
    this.computePurchaseOrder(purchaseOrderMerged);
    purchaseOrderRepo.save(purchaseOrderMerged);
    this.removeOldPurchaseOrders(purchaseOrderList);
    return purchaseOrderMerged;
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Transactional(com.google.inject.persist.Transactional)

Example 69 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method attachToNewPurchaseOrder.

// Attachment of all purchase order lines to new purchase order
public void attachToNewPurchaseOrder(List<PurchaseOrder> purchaseOrderList, PurchaseOrder purchaseOrderMerged) {
    for (PurchaseOrder purchaseOrder : purchaseOrderList) {
        int countLine = 1;
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            purchaseOrderLine.setSequence(countLine * 10);
            purchaseOrderMerged.addPurchaseOrderLineListItem(purchaseOrderLine);
            countLine++;
        }
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 70 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder 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)

Aggregations

PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)84 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)26 AxelorException (com.axelor.exception.AxelorException)26 Transactional (com.google.inject.persist.Transactional)16 BigDecimal (java.math.BigDecimal)12 Company (com.axelor.apps.base.db.Company)11 Context (com.axelor.rpc.Context)10 Partner (com.axelor.apps.base.db.Partner)9 Product (com.axelor.apps.base.db.Product)9 ArrayList (java.util.ArrayList)9 Invoice (com.axelor.apps.account.db.Invoice)7 List (java.util.List)7 PurchaseOrderRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)6 SaleOrder (com.axelor.apps.sale.db.SaleOrder)6 PurchaseOrderSupplychainService (com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService)6 LocalDate (java.time.LocalDate)6 PurchaseOrderService (com.axelor.apps.purchase.service.PurchaseOrderService)5 StockMove (com.axelor.apps.stock.db.StockMove)5 Unit (com.axelor.apps.base.db.Unit)4 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)4