Search in sources :

Example 1 with PurchaseOrderSupplierLine

use of com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine in project axelor-open-suite by axelor.

the class PurchaseOrderSupplierLineController method accept.

public void accept(ActionRequest request, ActionResponse response) {
    PurchaseOrderSupplierLine purchaseOrderSupplierLine = Beans.get(PurchaseOrderSupplierLineRepository.class).find(request.getContext().asType(PurchaseOrderSupplierLine.class).getId());
    if (purchaseOrderSupplierLine.getPurchaseOrderLine() == null && request.getContext().getParent() != null) {
        purchaseOrderSupplierLine.setPurchaseOrderLine(Beans.get(PurchaseOrderLineRepository.class).find(request.getContext().getParent().asType(PurchaseOrderLine.class).getId()));
    }
    try {
        Beans.get(PurchaseOrderSupplierLineService.class).accept(purchaseOrderSupplierLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderSupplierLineRepository(com.axelor.apps.suppliermanagement.db.repo.PurchaseOrderSupplierLineRepository) PurchaseOrderSupplierLineService(com.axelor.apps.suppliermanagement.service.PurchaseOrderSupplierLineService) PurchaseOrderSupplierLine(com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine)

Example 2 with PurchaseOrderSupplierLine

use of com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine in project axelor-open-suite by axelor.

the class PurchaseOrderSupplierLineController method supplierPartnerDomain.

/**
 * Called on supplier partner select. Set the domain for the field supplierPartner
 *
 * @param request
 * @param response
 */
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
    PurchaseOrderSupplierLine purchaseOrderSupplierLine = request.getContext().asType(PurchaseOrderSupplierLine.class);
    PurchaseOrderLine purchaseOrderLine = purchaseOrderSupplierLine.getPurchaseOrderLine();
    if (purchaseOrderLine == null) {
        purchaseOrderLine = request.getContext().getParent().asType(PurchaseOrderLine.class);
    }
    PurchaseOrder purchaseOrder = request.getContext().getParent().getParent().asType(PurchaseOrder.class);
    if (purchaseOrder.getId() != null) {
        purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    }
    Company company = purchaseOrder.getCompany();
    String domain = "";
    if (Beans.get(AppPurchaseService.class).getAppPurchase().getManageSupplierCatalog() && purchaseOrderLine.getProduct() != null && !purchaseOrderLine.getProduct().getSupplierCatalogList().isEmpty()) {
        domain += "self.id != " + company.getPartner().getId() + " AND self.id IN " + purchaseOrderLine.getProduct().getSupplierCatalogList().stream().map(s -> s.getSupplierPartner().getId()).collect(Collectors.toList()).toString().replace('[', '(').replace(']', ')');
        String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(company, BlockingRepository.PURCHASE_BLOCKING);
        if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
            domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
        }
    } else {
        domain += "self.id = 0";
    }
    domain += " AND " + company.getId() + " in (SELECT id FROM self.companySet)";
    response.setAttr("supplierPartner", "domain", domain);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) PurchaseOrderSupplierLine(com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine) BlockingService(com.axelor.apps.base.service.BlockingService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)2 PurchaseOrderSupplierLine (com.axelor.apps.suppliermanagement.db.PurchaseOrderSupplierLine)2 Company (com.axelor.apps.base.db.Company)1 BlockingService (com.axelor.apps.base.service.BlockingService)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 PurchaseOrderSupplierLineRepository (com.axelor.apps.suppliermanagement.db.repo.PurchaseOrderSupplierLineRepository)1 PurchaseOrderSupplierLineService (com.axelor.apps.suppliermanagement.service.PurchaseOrderSupplierLineService)1