Search in sources :

Example 1 with SaleOrderComputeService

use of com.axelor.apps.sale.service.saleorder.SaleOrderComputeService 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;
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Aggregations

PaymentMode (com.axelor.apps.account.db.PaymentMode)1 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)1 Company (com.axelor.apps.base.db.Company)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)1 SaleOrderComputeService (com.axelor.apps.sale.service.saleorder.SaleOrderComputeService)1 SaleOrderCreateService (com.axelor.apps.sale.service.saleorder.SaleOrderCreateService)1 SaleOrderWorkflowService (com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService)1 Transactional (com.google.inject.persist.Transactional)1