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