Search in sources :

Example 6 with PurchaseOrder

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

the class IntercoServiceImpl method generateIntercoPurchaseFromSale.

@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder generateIntercoPurchaseFromSale(SaleOrder saleOrder) throws AxelorException {
    PurchaseOrderService purchaseOrderService = Beans.get(PurchaseOrderService.class);
    Company intercoCompany = findIntercoCompany(saleOrder.getClientPartner());
    // create purchase order
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setCompany(intercoCompany);
    purchaseOrder.setContactPartner(saleOrder.getContactPartner());
    purchaseOrder.setCurrency(saleOrder.getCurrency());
    purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
    purchaseOrder.setOrderDate(saleOrder.getCreationDate());
    purchaseOrder.setPriceList(saleOrder.getPriceList());
    purchaseOrder.setTradingName(saleOrder.getTradingName());
    purchaseOrder.setPurchaseOrderLineList(new ArrayList<>());
    purchaseOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, intercoCompany));
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
    purchaseOrder.setSupplierPartner(saleOrder.getCompany().getPartner());
    purchaseOrder.setTradingName(saleOrder.getTradingName());
    // in ati
    purchaseOrder.setInAti(saleOrder.getInAti());
    // copy payments
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(saleOrder.getPaymentMode());
    purchaseOrder.setPaymentMode(intercoPaymentMode);
    purchaseOrder.setPaymentCondition(saleOrder.getPaymentCondition());
    // copy delivery info
    purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
    purchaseOrder.setStockLocation(Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(intercoCompany));
    purchaseOrder.setShipmentMode(saleOrder.getShipmentMode());
    purchaseOrder.setFreightCarrierMode(saleOrder.getFreightCarrierMode());
    // copy timetable info
    purchaseOrder.setExpectedRealisationDate(saleOrder.getExpectedRealisationDate());
    purchaseOrder.setAmountToBeSpreadOverTheTimetable(saleOrder.getAmountToBeSpreadOverTheTimetable());
    // create lines
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList != null) {
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            this.createIntercoPurchaseLineFromSaleLine(saleOrderLine, purchaseOrder);
        }
    }
    purchaseOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
    // compute the purchase order
    purchaseOrderService.computePurchaseOrder(purchaseOrder);
    purchaseOrder.setCreatedByInterco(true);
    Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseOrderCreateRequested()) {
        Beans.get(PurchaseOrderService.class).requestPurchaseOrder(purchaseOrder);
    }
    saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
    purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
    return purchaseOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 7 with PurchaseOrder

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

the class BudgetSupplychainService method updateBudgetLinesFromPurchaseOrder.

public void updateBudgetLinesFromPurchaseOrder(PurchaseOrder purchaseOrder) {
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList == null) {
        return;
    }
    purchaseOrderLineList.stream().flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
        Budget budget = budgetDistribution.getBudget();
        updateLines(budget);
        computeTotalAmountCommitted(budget);
    });
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetLineRepository(com.axelor.apps.account.db.repo.BudgetLineRepository) Budget(com.axelor.apps.account.db.Budget) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) Inject(com.google.inject.Inject) Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) BudgetService(com.axelor.apps.account.service.BudgetService) List(java.util.List) BudgetLine(com.axelor.apps.account.db.BudgetLine) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetRepository(com.axelor.apps.account.db.repo.BudgetRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) DateTool(com.axelor.apps.tool.date.DateTool) Budget(com.axelor.apps.account.db.Budget)

Example 8 with PurchaseOrder

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

the class ForecastRecapServiceImpl method getOrderAmount.

protected BigDecimal getOrderAmount(ForecastRecap forecastRecap, ForecastRecapLineType forecastRecapLineType, Model forecastModel) {
    BigDecimal sumAmountInvoices;
    BigDecimal orderTotal;
    int operationTypeRefund;
    int operationTypeInvoice;
    if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER) {
        operationTypeRefund = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
        operationTypeInvoice = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
        SaleOrder saleOrder = (SaleOrder) forecastModel;
        orderTotal = saleOrder.getInTaxTotal();
    } else {
        operationTypeRefund = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
        operationTypeInvoice = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
        PurchaseOrder purchaseOrder = (PurchaseOrder) forecastModel;
        orderTotal = purchaseOrder.getInTaxTotal();
    }
    TypedQuery<BigDecimal> sumAmountInvoiceQuery = JPA.em().createQuery("SELECT SUM(CASE WHEN operationTypeSelect = :operationTypeInvoice " + "THEN invoice.inTaxTotal " + "ELSE (invoice.inTaxTotal * -1) " + "END) " + "FROM Invoice invoice " + "WHERE ((invoice.statusSelect IN (:invoiceStatusSelect) " + "AND operationTypeSelect = :operationTypeInvoice) " + "OR (invoice.statusSelect IN (:refundStatusSelect) " + "AND operationTypeSelect = :operationTypeRefund )) " + (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER ? "AND invoice.saleOrder.id = :orderId" : "AND invoice.purchaseOrder.id = :orderId"), BigDecimal.class).setParameter("orderId", forecastModel.getId()).setParameter("operationTypeInvoice", operationTypeInvoice).setParameter("invoiceStatusSelect", invoiceStatusMap.get(operationTypeInvoice)).setParameter("operationTypeRefund", operationTypeRefund).setParameter("refundStatusSelect", invoiceStatusMap.get(operationTypeRefund));
    sumAmountInvoices = Optional.ofNullable(sumAmountInvoiceQuery.getSingleResult()).orElse(BigDecimal.ZERO);
    return orderTotal.subtract(sumAmountInvoices);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 9 with PurchaseOrder

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

the class PurchaseOrderProjectController method updateLines.

public void updateLines(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
        purchaseOrder = Beans.get(ProjectAnalyticMoveLineService.class).updateLines(purchaseOrder);
        response.setValue("purchaseOrderLineList", purchaseOrder.getPurchaseOrderLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 10 with PurchaseOrder

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

the class PurchaseOrderController method fillDefaultPrintingSettings.

/**
 * Called on trading name change. Set the default value for {@link PurchaseOrder#printingSettings}
 *
 * @param request
 * @param response
 */
public void fillDefaultPrintingSettings(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        response.setValue("printingSettings", Beans.get(TradingNameService.class).getDefaultPrintingSettings(purchaseOrder.getTradingName(), purchaseOrder.getCompany()));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) AxelorException(com.axelor.exception.AxelorException)

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