Search in sources :

Example 31 with PurchaseOrder

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

the class SupplierViewController method getLastOrder.

public void getLastOrder(ActionRequest request, ActionResponse response) {
    try {
        SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
        User user = supplierViewService.getSupplierUser();
        String domain = Beans.get(SupplierViewService.class).getLastPurchaseOrderOfSupplier(user);
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).all().filter(domain).fetchOne();
        if (purchaseOrder != null) {
            response.setView(ActionView.define(I18n.get("Last order")).model(PurchaseOrder.class.getName()).add("form", "purchase-order-form").context("_showRecord", purchaseOrder.getId()).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) SupplierViewService(com.axelor.apps.supplierportal.service.SupplierViewService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)

Example 32 with PurchaseOrder

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

the class PurchaseOrderServiceProductionImpl method mergePurchaseOrders.

@Override
public PurchaseOrder mergePurchaseOrders(List<PurchaseOrder> purchaseOrderList, Currency currency, Partner supplierPartner, Company company, StockLocation stockLocation, Partner contactPartner, PriceList priceList, TradingName tradingName) throws AxelorException {
    PurchaseOrder mergedPurchaseOrder = super.mergePurchaseOrders(purchaseOrderList, currency, supplierPartner, company, stockLocation, contactPartner, priceList, tradingName);
    this.setMergedPurchaseOrderForManufOrder(mergedPurchaseOrder, purchaseOrderList);
    return mergedPurchaseOrder;
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 33 with PurchaseOrder

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

the class StockMoveMultiInvoiceServiceImpl method fillReferenceInvoiceFromMultiInStockMove.

/**
 * Fill external and internal reference in the given invoice, from the list of stock moves.
 *
 * @param stockMoveList
 * @param dummyInvoice
 */
protected void fillReferenceInvoiceFromMultiInStockMove(List<StockMove> stockMoveList, Invoice dummyInvoice) {
    // Concat sequence, internal ref and external ref from all saleOrder
    List<String> externalRefList = new ArrayList<>();
    List<String> internalRefList = new ArrayList<>();
    for (StockMove stockMove : stockMoveList) {
        PurchaseOrder purchaseOrder = StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null ? purchaseOrderRepository.find(stockMove.getOriginId()) : null;
        if (purchaseOrder != null) {
            externalRefList.add(purchaseOrder.getExternalReference());
        }
        internalRefList.add(stockMove.getStockMoveSeq() + (purchaseOrder != null ? (":" + purchaseOrder.getPurchaseOrderSeq()) : ""));
    }
    String externalRef = String.join("|", externalRefList);
    String internalRef = String.join("|", internalRefList);
    dummyInvoice.setExternalReference(StringTool.cutTooLongString(externalRef));
    dummyInvoice.setInternalReference(StringTool.cutTooLongString(internalRef));
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 34 with PurchaseOrder

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

the class StockMoveMultiInvoiceServiceImpl method createDummyInInvoice.

/**
 * Create a dummy invoice to hold fields used to generate the invoice which will be saved.
 *
 * @param stockMove an in stock move.
 * @return the created dummy invoice.
 */
protected Invoice createDummyInInvoice(StockMove stockMove) {
    Invoice dummyInvoice = new Invoice();
    if (stockMove.getOriginId() != null && StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        dummyInvoice.setCurrency(purchaseOrder.getCurrency());
        dummyInvoice.setPartner(purchaseOrder.getSupplierPartner());
        dummyInvoice.setCompany(purchaseOrder.getCompany());
        dummyInvoice.setTradingName(purchaseOrder.getTradingName());
        dummyInvoice.setPaymentCondition(purchaseOrder.getPaymentCondition());
        dummyInvoice.setPaymentMode(purchaseOrder.getPaymentMode());
        dummyInvoice.setContactPartner(purchaseOrder.getContactPartner());
        dummyInvoice.setPriceList(purchaseOrder.getPriceList());
        dummyInvoice.setInAti(purchaseOrder.getInAti());
    } else {
        dummyInvoice.setCurrency(stockMove.getCompany().getCurrency());
        dummyInvoice.setPartner(stockMove.getPartner());
        dummyInvoice.setCompany(stockMove.getCompany());
        dummyInvoice.setTradingName(stockMove.getTradingName());
        dummyInvoice.setAddress(stockMove.getFromAddress());
        dummyInvoice.setAddressStr(stockMove.getFromAddressStr());
    }
    return dummyInvoice;
}
Also used : RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 35 with PurchaseOrder

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

the class WorkflowCancelServiceSupplychainImpl method purchaseOrderLineProcess.

public PurchaseOrder purchaseOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
    if (purchaseOrderLine == null) {
        return null;
    }
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
    // If is it a refund invoice, so we negate the amount invoiced
    if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
        invoicedAmountToAdd = invoicedAmountToAdd.negate();
    }
    // Update invoiced amount on purchase order line
    if (!invoice.getCurrency().equals(purchaseOrder.getCurrency()) && purchaseOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
        // If the purchase order currency is different from the invoice currency, use company currency
        // to calculate a rate. This rate will be applied to purchase order line
        BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
        BigDecimal rate = currentCompanyInvoicedAmount.divide(purchaseOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
        invoicedAmountToAdd = rate.multiply(purchaseOrderLine.getExTaxTotal());
    }
    purchaseOrderLine.setAmountInvoiced(purchaseOrderLine.getAmountInvoiced().subtract(invoicedAmountToAdd));
    return purchaseOrder;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) BigDecimal(java.math.BigDecimal)

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