use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class SaleOrderController method generatePurchaseOrdersFromSelectedSOLines.
@SuppressWarnings({ "unchecked" })
public void generatePurchaseOrdersFromSelectedSOLines(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
try {
if (saleOrder.getId() != null) {
Partner supplierPartner = null;
List<Long> saleOrderLineIdSelected = new ArrayList<>();
Boolean isDirectOrderLocation = false;
Boolean noProduct = true;
Map<String, Object> values = getSelectedId(request, response, saleOrder);
supplierPartner = (Partner) values.get("supplierPartner");
saleOrderLineIdSelected = (List<Long>) values.get("saleOrderLineIdSelected");
isDirectOrderLocation = (Boolean) values.get("isDirectOrderLocation");
if (supplierPartner == null) {
saleOrderLineIdSelected = new ArrayList<>();
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
if (saleOrderLine.isSelected()) {
if (supplierPartner == null) {
supplierPartner = saleOrderLine.getSupplierPartner();
}
if (saleOrderLine.getProduct() != null) {
noProduct = false;
}
saleOrderLineIdSelected.add(saleOrderLine.getId());
}
}
if (saleOrderLineIdSelected.isEmpty() || noProduct) {
response.setFlash(I18n.get(IExceptionMessage.SO_LINE_PURCHASE_AT_LEAST_ONE));
} else {
response.setView(ActionView.define("SaleOrder").model(SaleOrder.class.getName()).add("form", "sale-order-generate-po-select-supplierpartner-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).context("supplierPartnerId", ((supplierPartner != null) ? supplierPartner.getId() : 0L)).context("saleOrderLineIdSelected", Joiner.on(",").join(saleOrderLineIdSelected)).map());
}
} else {
List<SaleOrderLine> saleOrderLinesSelected = JPA.all(SaleOrderLine.class).filter("self.id IN (:saleOderLineIdList)").bind("saleOderLineIdList", saleOrderLineIdSelected).fetch();
PurchaseOrder purchaseOrder = Beans.get(SaleOrderPurchaseService.class).createPurchaseOrder(supplierPartner, saleOrderLinesSelected, Beans.get(SaleOrderRepository.class).find(saleOrder.getId()));
response.setView(ActionView.define(I18n.get("Purchase order")).model(PurchaseOrder.class.getName()).add("form", "purchase-order-form").param("forceEdit", "true").context("_showRecord", String.valueOf(purchaseOrder.getId())).map());
if (isDirectOrderLocation == false) {
response.setCanClose(true);
}
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class TimetableController method generateInvoice.
public void generateInvoice(ActionRequest request, ActionResponse response) throws AxelorException {
Timetable timetable = request.getContext().asType(Timetable.class);
timetable = Beans.get(TimetableRepository.class).find(timetable.getId());
Context parentContext = request.getContext().getParent();
if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
SaleOrder saleOrder = parentContext.asType(SaleOrder.class);
if (saleOrder.getStatusSelect() < SaleOrderRepository.STATUS_ORDER_CONFIRMED) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_SALE_ORDER_NOT_CONFIRMED));
return;
}
}
if (parentContext != null && parentContext.getContextClass().equals(PurchaseOrder.class)) {
PurchaseOrder purchaseOrder = parentContext.asType(PurchaseOrder.class);
if (purchaseOrder.getStatusSelect() < PurchaseOrderRepository.STATUS_VALIDATED) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_PURCHASE_OREDR_NOT_VALIDATED));
return;
}
}
if (timetable.getInvoice() != null) {
response.setAlert(I18n.get(IExceptionMessage.TIMETABLE_INVOICE_ALREADY_GENERATED));
return;
}
Invoice invoice = timetableService.generateInvoice(timetable);
response.setReload(true);
response.setView(ActionView.define(I18n.get("Invoice generated")).model("com.axelor.apps.account.db.Invoice").add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", invoice.getId().toString()).map());
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class ImportSupplyChain method importPurchaseOrderFromSupplyChain.
@Transactional
public Object importPurchaseOrderFromSupplyChain(Object bean, Map<String, Object> values) {
try {
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
PurchaseOrder purchaseOrder = (PurchaseOrder) bean;
int status = purchaseOrder.getStatusSelect();
purchaseOrder = (PurchaseOrder) importPurchaseOrder.importPurchaseOrder(bean, values);
for (PurchaseOrderLine line : purchaseOrder.getPurchaseOrderLineList()) {
Product product = line.getProduct();
if (product.getMassUnit() == null) {
product.setMassUnit(stockConfigService.getStockConfig(purchaseOrder.getCompany()).getCustomsMassUnit());
}
}
if (status == PurchaseOrderRepository.STATUS_VALIDATED || status == PurchaseOrderRepository.STATUS_FINISHED) {
purchaseOrderWorkflowService.validatePurchaseOrder(purchaseOrder);
}
if (status == PurchaseOrderRepository.STATUS_FINISHED) {
List<Long> idList = purchaseOrderStockServiceImpl.createStockMoveFromPurchaseOrder(purchaseOrder);
for (Long id : idList) {
StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove);
stockMove.setRealDate(purchaseOrder.getDeliveryDate());
}
purchaseOrder.setValidationDate(purchaseOrder.getOrderDate());
purchaseOrder.setValidatedByUser(AuthUtils.getUser());
purchaseOrder.setSupplierPartner(purchaseOrderService.validateSupplier(purchaseOrder));
Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
String prefixSupplierSeq = "INV000";
invoice.setSupplierInvoiceNb(prefixSupplierSeq + purchaseOrder.getImportId());
invoice.setInternalReference(purchaseOrder.getInternalReference());
LocalDate date;
if (purchaseOrder.getValidationDate() != null) {
date = purchaseOrder.getValidationDate();
} else {
date = Beans.get(AppBaseService.class).getTodayDate(purchaseOrder.getCompany());
}
invoice.setInvoiceDate(date);
invoice.setOriginDate(date.minusDays(15));
invoiceService.validateAndVentilate(invoice);
purchaseOrderWorkflowService.finishPurchaseOrder(purchaseOrder);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
return null;
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderController method updateCostPrice.
public void updateCostPrice(ActionRequest request, ActionResponse response) {
try {
PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
Beans.get(PurchaseOrderService.class).updateCostPrice(Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId()));
} 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 showPurchaseOrder.
/**
* Called from grid or form purchase order view, print selected purchase order.
*
* @param request
* @param response
* @return
*/
@SuppressWarnings("unchecked")
public void showPurchaseOrder(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String fileLink;
String title;
PurchaseOrderPrintService purchaseOrderPrintService = Beans.get(PurchaseOrderPrintService.class);
try {
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = Lists.transform((List) request.getContext().get("_ids"), new Function<Object, Long>() {
@Nullable
@Override
public Long apply(@Nullable Object input) {
return Long.parseLong(input.toString());
}
});
fileLink = purchaseOrderPrintService.printPurchaseOrders(ids);
title = I18n.get("Purchase orders");
} else if (context.get("id") != null) {
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
title = purchaseOrderPrintService.getFileName(purchaseOrder);
fileLink = purchaseOrderPrintService.printPurchaseOrder(purchaseOrder, ReportSettings.FORMAT_PDF);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PURCHASE_ORDER_SELECTED_FOR_PRINTING));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations