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;
}
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;
}
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);
}
}
Aggregations