Search in sources :

Example 1 with PackLine

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

the class PackLineController method getPack.

public Pack getPack(Context context) {
    Context parentContext = context.getParent();
    PackLine packLine = context.asType(PackLine.class);
    Pack pack = packLine.getPack();
    if (parentContext != null && parentContext.getContextClass().equals(Pack.class)) {
        pack = parentContext.asType(Pack.class);
    }
    return pack;
}
Also used : Context(com.axelor.rpc.Context) Pack(com.axelor.apps.sale.db.Pack) PackLine(com.axelor.apps.sale.db.PackLine)

Example 2 with PackLine

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

the class SaleOrderServiceImpl method addPack.

@Override
@Transactional
public SaleOrder addPack(SaleOrder saleOrder, Pack pack, BigDecimal packQty) {
    List<PackLine> packLineList = pack.getComponents();
    if (ObjectUtils.isEmpty(packLineList)) {
        return saleOrder;
    }
    packLineList.sort(Comparator.comparing(PackLine::getSequence));
    Integer sequence = -1;
    List<SaleOrderLine> soLines = saleOrder.getSaleOrderLineList();
    if (soLines != null && !soLines.isEmpty()) {
        sequence = soLines.stream().mapToInt(SaleOrderLine::getSequence).max().getAsInt();
    }
    BigDecimal conversionRate = new BigDecimal(1.00);
    if (pack.getCurrency() != null && !pack.getCurrency().getCode().equals(saleOrder.getCurrency().getCode())) {
        try {
            conversionRate = Beans.get(CurrencyConversionFactory.class).getCurrencyConversionService().convert(pack.getCurrency(), saleOrder.getCurrency());
        } catch (MalformedURLException | JSONException | AxelorException e) {
            TraceBackService.trace(e);
        }
    }
    if (Boolean.FALSE.equals(pack.getDoNotDisplayHeaderAndEndPack())) {
        if (saleOrderLineService.getPackLineTypes(packLineList) == null || !saleOrderLineService.getPackLineTypes(packLineList).contains(PackLineRepository.TYPE_START_OF_PACK)) {
            sequence++;
        }
        soLines = saleOrderLineService.createNonStandardSOLineFromPack(pack, saleOrder, packQty, soLines, sequence);
    }
    SaleOrderLine soLine;
    for (PackLine packLine : packLineList) {
        if (packLine.getTypeSelect() != PackLineRepository.TYPE_NORMAL && Boolean.TRUE.equals(pack.getDoNotDisplayHeaderAndEndPack())) {
            continue;
        }
        soLine = saleOrderLineService.createSaleOrderLine(packLine, saleOrder, packQty, conversionRate, ++sequence);
        if (soLine != null) {
            soLine.setSaleOrder(saleOrder);
            soLines.add(soLine);
        }
    }
    if (soLines != null && !soLines.isEmpty()) {
        try {
            saleOrder = Beans.get(SaleOrderComputeService.class).computeSaleOrder(saleOrder);
            Beans.get(SaleOrderMarginService.class).computeMarginSaleOrder(saleOrder);
        } catch (AxelorException e) {
            TraceBackService.trace(e);
        }
        Beans.get(SaleOrderRepository.class).save(saleOrder);
    }
    return saleOrder;
}
Also used : AxelorException(com.axelor.exception.AxelorException) MalformedURLException(java.net.MalformedURLException) JSONException(wslite.json.JSONException) CurrencyConversionFactory(com.axelor.apps.base.service.currency.CurrencyConversionFactory) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) PackLine(com.axelor.apps.sale.db.PackLine) Transactional(com.google.inject.persist.Transactional)

Example 3 with PackLine

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

the class PackLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PackLine packLine = context.asType(PackLine.class);
    Pack pack = this.getPack(context);
    Product product = packLine.getProduct();
    PackLineService packLineService = Beans.get(PackLineService.class);
    if (product == null) {
        packLine = packLineService.resetProductInformation(packLine);
        response.setValues(packLine);
        return;
    }
    try {
        packLine = packLineService.computeProductInformation(pack, packLine);
        response.setValues(packLine);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Product(com.axelor.apps.base.db.Product) Pack(com.axelor.apps.sale.db.Pack) PackLineService(com.axelor.apps.sale.service.PackLineService) PackLine(com.axelor.apps.sale.db.PackLine)

Aggregations

PackLine (com.axelor.apps.sale.db.PackLine)3 Pack (com.axelor.apps.sale.db.Pack)2 Context (com.axelor.rpc.Context)2 Product (com.axelor.apps.base.db.Product)1 CurrencyConversionFactory (com.axelor.apps.base.service.currency.CurrencyConversionFactory)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)1 PackLineService (com.axelor.apps.sale.service.PackLineService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 BigDecimal (java.math.BigDecimal)1 MalformedURLException (java.net.MalformedURLException)1 JSONException (wslite.json.JSONException)1