Search in sources :

Example 81 with SaleOrderLine

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

the class SaleOrderComputeServiceImpl method computePackTotal.

@Override
public void computePackTotal(SaleOrder saleOrder) {
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (ObjectUtils.isEmpty(saleOrderLineList) || !saleOrderLineService.hasEndOfPackTypeLine(saleOrderLineList)) {
        return;
    }
    BigDecimal totalExTaxTotal = BigDecimal.ZERO;
    BigDecimal totalInTaxTotal = BigDecimal.ZERO;
    saleOrderLineList.sort(Comparator.comparing(SaleOrderLine::getSequence));
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        switch(saleOrderLine.getTypeSelect()) {
            case SaleOrderLineRepository.TYPE_NORMAL:
                totalExTaxTotal = totalExTaxTotal.add(saleOrderLine.getExTaxTotal());
                totalInTaxTotal = totalInTaxTotal.add(saleOrderLine.getInTaxTotal());
                break;
            case SaleOrderLineRepository.TYPE_TITLE:
                break;
            case SaleOrderLineRepository.TYPE_START_OF_PACK:
                totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
                break;
            case SaleOrderLineRepository.TYPE_END_OF_PACK:
                saleOrderLine.setQty(BigDecimal.ZERO);
                saleOrderLine.setExTaxTotal(saleOrderLine.getIsShowTotal() ? totalExTaxTotal : BigDecimal.ZERO);
                saleOrderLine.setInTaxTotal(saleOrderLine.getIsShowTotal() ? totalInTaxTotal : BigDecimal.ZERO);
                totalExTaxTotal = totalInTaxTotal = BigDecimal.ZERO;
                break;
            default:
                break;
        }
    }
    saleOrder.setSaleOrderLineList(saleOrderLineList);
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 82 with SaleOrderLine

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

the class SaleOrderCreateServiceImpl method updateSaleOrderLineList.

public void updateSaleOrderLineList(SaleOrder saleOrder) throws AxelorException {
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList != null) {
        SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            if (saleOrderLine.getProduct() != null) {
                saleOrderLineService.fillPrice(saleOrderLine, saleOrder);
                saleOrderLineService.computeValues(saleOrder, saleOrderLine);
            }
        }
    }
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 83 with SaleOrderLine

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

the class SaleOrderController method fillSaleOrderLinesEstimatedDate.

public void fillSaleOrderLinesEstimatedDate(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList != null) {
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            Integer deliveryState = saleOrderLine.getDeliveryState();
            if (!deliveryState.equals(SaleOrderLineRepository.DELIVERY_STATE_DELIVERED) && !deliveryState.equals(SaleOrderLineRepository.DELIVERY_STATE_PARTIALLY_DELIVERED)) {
                saleOrderLine.setEstimatedDelivDate(saleOrder.getDeliveryDate());
            }
        }
    }
    response.setValue("saleOrderLineList", saleOrderLineList);
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 84 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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);
    }
}
Also used : ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException) SaleOrderPurchaseService(com.axelor.apps.supplychain.service.SaleOrderPurchaseService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Partner(com.axelor.apps.base.db.Partner)

Example 85 with SaleOrderLine

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

the class SaleOrderController method fillDefaultValueWizard.

/**
 * Called on load of sale order invoicing wizard view. Fill dummy field with default value to
 * avoid issues with null values.
 *
 * @param request
 * @param response
 */
public void fillDefaultValueWizard(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        List<Map<String, Object>> saleOrderLineList = new ArrayList<>();
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            Map<String, Object> saleOrderLineMap = Mapper.toMap(saleOrderLine);
            saleOrderLineMap.put(SO_LINES_WIZARD_QTY_TO_INVOICE_FIELD, BigDecimal.ZERO);
            saleOrderLineList.add(saleOrderLineMap);
        }
        response.setValue("amountToInvoice", BigDecimal.ZERO);
        response.setValue("saleOrderLineList", saleOrderLineList);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AxelorException(com.axelor.exception.AxelorException)

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