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