Search in sources :

Example 91 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method updateReservationDate.

/**
 * Called from sale order line, on desired delivery date change. Call {@link
 * SaleOrderLineServiceSupplyChain#updateStockMoveReservationDateTime(SaleOrderLine)}.
 *
 * @param request
 * @param response
 */
public void updateReservationDate(ActionRequest request, ActionResponse response) {
    try {
        SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
        saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
        Beans.get(SaleOrderLineServiceSupplyChain.class).updateStockMoveReservationDateTime(saleOrderLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 92 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method computeAnalyticDistribution.

public void computeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    if (Beans.get(AppAccountService.class).getAppAccount().getManageAnalyticAccounting()) {
        saleOrderLine = Beans.get(SaleOrderLineServiceSupplyChain.class).computeAnalyticDistribution(saleOrderLine);
        response.setValue("analyticDistributionTemplate", saleOrderLine.getAnalyticDistributionTemplate());
        response.setValue("analyticMoveLineList", saleOrderLine.getAnalyticMoveLineList());
    }
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 93 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class ImportSupplyChain method importSaleOrderFromSupplyChain.

@Transactional
public Object importSaleOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        SaleOrderWorkflowService saleOrderWorkflowService = Beans.get(SaleOrderWorkflowService.class);
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        SaleOrder saleOrder = (SaleOrder) importSaleOrder.importSaleOrder(bean, values);
        for (SaleOrderLine line : saleOrder.getSaleOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(saleOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_FINALIZED_QUOTATION) {
            // taskSaleOrderService.createTasks(saleOrder); TODO once we will have done the generation//
            // of tasks in project module
            saleOrderWorkflowService.confirmSaleOrder(saleOrder);
            // Beans.get(SaleOrderPurchaseService.class).createPurchaseOrders(saleOrder);
            // productionOrderSaleOrderService.generateProductionOrder(saleOrder);
            // saleOrder.setClientPartner(saleOrderWorkflowService.validateCustomer(saleOrder));
            // Generate invoice from sale order
            Invoice invoice = Beans.get(SaleOrderInvoiceService.class).generateInvoice(saleOrder);
            if (saleOrder.getConfirmationDateTime() != null) {
                invoice.setInvoiceDate(saleOrder.getConfirmationDateTime().toLocalDate());
            } else {
                invoice.setInvoiceDate(Beans.get(AppBaseService.class).getTodayDate(saleOrder.getCompany()));
            }
            invoiceService.validateAndVentilate(invoice);
            List<Long> idList = saleOrderStockService.createStocksMovesFromSaleOrder(saleOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
                    stockMoveService.copyQtyToRealQty(stockMove);
                    stockMoveService.validate(stockMove);
                    if (saleOrder.getConfirmationDateTime() != null) {
                        stockMove.setRealDate(saleOrder.getConfirmationDateTime().toLocalDate());
                    }
                }
            }
        }
        saleOrderRepo.save(saleOrder);
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 94 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class TestSaleOrderStockService method testUpdateDeliveryStatePartiallyDeliveredLinesSaleOrder.

@Test
public void testUpdateDeliveryStatePartiallyDeliveredLinesSaleOrder() throws AxelorException {
    SaleOrder saleOrder = new SaleOrder();
    saleOrder.setSaleOrderLineList(new ArrayList<>());
    SaleOrderLine saleOrderLine1 = new SaleOrderLine();
    SaleOrderLine saleOrderLine2 = new SaleOrderLine();
    SaleOrderLine saleOrderLine3 = new SaleOrderLine();
    saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
    saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_NOT_DELIVERED);
    saleOrderLine3.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
    saleOrder.addSaleOrderLineListItem(saleOrderLine1);
    saleOrder.addSaleOrderLineListItem(saleOrderLine2);
    saleOrder.addSaleOrderLineListItem(saleOrderLine3);
    saleOrderStockService.updateDeliveryState(saleOrder);
    Assert.assertEquals(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED, (int) saleOrder.getDeliveryState());
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Test(org.junit.Test)

Example 95 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class TestSaleOrderStockService method testUpdateDeliveryStatePartiallyDeliveredSaleOrder.

@Test
public void testUpdateDeliveryStatePartiallyDeliveredSaleOrder() throws AxelorException {
    SaleOrder saleOrder = new SaleOrder();
    SaleOrderLine saleOrderLine1 = new SaleOrderLine();
    SaleOrderLine saleOrderLine2 = new SaleOrderLine();
    saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
    saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_NOT_DELIVERED);
    saleOrder.addSaleOrderLineListItem(saleOrderLine1);
    saleOrder.addSaleOrderLineListItem(saleOrderLine2);
    saleOrderStockService.updateDeliveryState(saleOrder);
    Assert.assertEquals(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED, (int) saleOrder.getDeliveryState());
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Test(org.junit.Test)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6