use of com.axelor.apps.sale.service.saleorder.SaleOrderCreateService in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoSaleFromPurchase.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
// create sale order
SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
// in ati
saleOrder.setInAti(purchaseOrder.getInAti());
// copy date
saleOrder.setOrderDate(purchaseOrder.getOrderDate());
// copy payments
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
saleOrder.setPaymentMode(intercoPaymentMode);
saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
// copy delivery info
saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
// get stock location
saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
// copy timetable info
saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
// create lines
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLineList != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
}
}
saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
// compute the sale order
saleOrderComputeService.computeSaleOrder(saleOrder);
saleOrder.setCreatedByInterco(true);
Beans.get(SaleOrderRepository.class).save(saleOrder);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
}
purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
return saleOrder;
}
Aggregations