Search in sources :

Example 61 with PurchaseOrder

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

the class PurchaseOrderController method validateSupplier.

public void validateSupplier(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    response.setValue("supplierPartner", Beans.get(PurchaseOrderService.class).validateSupplier(purchaseOrder));
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 62 with PurchaseOrder

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

the class PurchaseOrderController method validate.

public void validate(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
        Beans.get(PurchaseOrderWorkflowService.class).validatePurchaseOrder(purchaseOrder);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) AxelorException(com.axelor.exception.AxelorException) PurchaseOrderWorkflowService(com.axelor.apps.purchase.service.PurchaseOrderWorkflowService)

Example 63 with PurchaseOrder

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

the class PurchaseOrderController method filterPrintingSettings.

/**
 * Called on printing settings select. Set the domain for {@link PurchaseOrder#printingSettings}
 *
 * @param request
 * @param response
 */
public void filterPrintingSettings(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        List<PrintingSettings> printingSettingsList = Beans.get(TradingNameService.class).getPrintingSettingsList(purchaseOrder.getTradingName(), purchaseOrder.getCompany());
        String domain = String.format("self.id IN (%s)", !printingSettingsList.isEmpty() ? StringTool.getIdListString(printingSettingsList) : "0");
        response.setAttr("printingSettings", "domain", domain);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PrintingSettings(com.axelor.apps.base.db.PrintingSettings) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) TradingNameService(com.axelor.apps.base.service.TradingNameService) AxelorException(com.axelor.exception.AxelorException)

Example 64 with PurchaseOrder

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

the class PurchaseOrderLineController method compute.

public void compute(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
        Map<String, BigDecimal> map = Beans.get(PurchaseOrderLineService.class).compute(purchaseOrderLine, purchaseOrder);
        response.setValues(map);
        response.setAttr("priceDiscounted", "hidden", map.getOrDefault("priceDiscounted", BigDecimal.ZERO).compareTo(purchaseOrder.getInAti() ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice()) == 0);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) BigDecimal(java.math.BigDecimal)

Example 65 with PurchaseOrder

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

the class PurchaseOrderLineController 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) {
    PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = request.getContext().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) BlockingService(com.axelor.apps.base.service.BlockingService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

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