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);
}
}
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;
}
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));
}
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;
}
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;
}
Aggregations