Search in sources :

Example 21 with PurchaseOrder

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

the class PurchaseOrderController method backToValidatedStatus.

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

Example 22 with PurchaseOrder

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

the class PurchaseOrderController method checkPurchaseOrderAnalyticDistributionTemplate.

/**
 * Called from purchase order form view when validating purchase order and analytic distribution
 * is required from company's purchase config.
 *
 * @param request
 * @param response
 */
public void checkPurchaseOrderAnalyticDistributionTemplate(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        List<String> productList = new ArrayList<String>();
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            if (purchaseOrderLine.getAnalyticDistributionTemplate() == null) {
                productList.add(purchaseOrderLine.getProduct().getFullName());
            }
        }
        if (productList != null && !productList.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.PURCHASE_ORDER_ANALYTIC_DISTRIBUTION_ERROR), productList);
        }
    } catch (AxelorException e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 23 with PurchaseOrder

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

the class PurchaseOrderController method generateBudgetDistribution.

public void generateBudgetDistribution(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (appAccountService.isApp("budget") && !appAccountService.getAppBudget().getManageMultiBudget()) {
        purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
        Beans.get(PurchaseOrderSupplychainService.class).generateBudgetDistribution(purchaseOrder);
        response.setValues(purchaseOrder);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderSupplychainService(com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService)

Example 24 with PurchaseOrder

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

the class PurchaseOrderInvoiceController method generateInvoice.

public void generateInvoice(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
    try {
        Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
        if (invoice != null) {
            response.setReload(true);
            response.setView(ActionView.define(I18n.get(IExceptionMessage.PO_INVOICE_2)).model(Invoice.class.getName()).add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").domain("self.purchaseOrder.id = " + String.valueOf(invoice.getId())).domain("self.operationTypeSelect = " + String.valueOf(invoice.getOperationTypeSelect())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("_showRecord", String.valueOf(invoice.getId())).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService)

Example 25 with PurchaseOrder

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

the class PurchaseOrderLineController method computeBudgetDistributionSumAmount.

public void computeBudgetDistributionSumAmount(ActionRequest request, ActionResponse response) {
    PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = request.getContext().getParent().asType(PurchaseOrder.class);
    Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrder);
    response.setValue("budgetDistributionSumAmount", purchaseOrderLine.getBudgetDistributionSumAmount());
    response.setValue("budgetDistributionList", purchaseOrderLine.getBudgetDistributionList());
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderLineServiceSupplychainImpl(com.axelor.apps.supplychain.service.PurchaseOrderLineServiceSupplychainImpl)

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