use of com.axelor.apps.sale.service.saleorder.SaleOrderLineService in project axelor-open-suite by axelor.
the class SaleOrderLineController method getDiscount.
public void getDiscount(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
if (saleOrder == null || saleOrderLine.getProduct() == null) {
return;
}
try {
Map<String, Object> discounts;
if (saleOrderLine.getProduct().getInAti()) {
discounts = saleOrderLineService.getDiscountsFromPriceLists(saleOrder, saleOrderLine, saleOrderLineService.getInTaxUnitPrice(saleOrder, saleOrderLine, saleOrderLine.getTaxLine()));
} else {
discounts = saleOrderLineService.getDiscountsFromPriceLists(saleOrder, saleOrderLine, saleOrderLineService.getExTaxUnitPrice(saleOrder, saleOrderLine, saleOrderLine.getTaxLine()));
}
if (discounts != null) {
BigDecimal price = (BigDecimal) discounts.get("price");
if (price != null && price.compareTo(saleOrderLine.getProduct().getInAti() ? saleOrderLine.getInTaxPrice() : saleOrderLine.getPrice()) != 0) {
if (saleOrderLine.getProduct().getInAti()) {
response.setValue("inTaxPrice", price);
response.setValue("price", saleOrderLineService.convertUnitPrice(true, saleOrderLine.getTaxLine(), price));
} else {
response.setValue("price", price);
response.setValue("inTaxPrice", saleOrderLineService.convertUnitPrice(false, saleOrderLine.getTaxLine(), price));
}
}
if (saleOrderLine.getProduct().getInAti() != saleOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
response.setValue("discountAmount", saleOrderLineService.convertUnitPrice(saleOrderLine.getProduct().getInAti(), saleOrderLine.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
} else {
response.setValue("discountAmount", discounts.get("discountAmount"));
}
response.setValue("discountTypeSelect", discounts.get("discountTypeSelect"));
}
} catch (Exception e) {
response.setFlash(e.getMessage());
}
}
use of com.axelor.apps.sale.service.saleorder.SaleOrderLineService in project axelor-open-suite by axelor.
the class SaleOrderLineController method computeProductDomain.
/**
* Called from sale order line form view, on product selection. Call {@link
* SaleOrderLineService#computeProductDomain(SaleOrderLine, SaleOrder)}.
*
* @param request
* @param response
*/
public void computeProductDomain(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
response.setAttr("product", "domain", saleOrderLineService.computeProductDomain(saleOrderLine, saleOrder));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.service.saleorder.SaleOrderLineService in project axelor-open-suite by axelor.
the class ImportSaleOrderLine method importSaleOrderLine.
public Object importSaleOrderLine(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof SaleOrderLine;
SaleOrderLine saleOrderLine = (SaleOrderLine) bean;
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
saleOrderLine.setTaxLine(saleOrderLineService.getTaxLine(saleOrderLine.getSaleOrder(), saleOrderLine));
saleOrderLineService.computeValues(saleOrderLine.getSaleOrder(), saleOrderLine);
return saleOrderLine;
}
use of com.axelor.apps.sale.service.saleorder.SaleOrderLineService in project axelor-open-suite by axelor.
the class SaleOrderLineController method getProductInformation.
/**
* Called by the sale order line form. Update all fields when the product is changed.
*
* @param request
* @param response
*/
public void getProductInformation(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
Product product = saleOrderLine.getProduct();
if (saleOrder == null || product == null) {
resetProductInformation(response, saleOrderLine);
return;
}
try {
product = Beans.get(ProductRepository.class).find(product.getId());
saleOrderLineService.computeProductInformation(saleOrderLine, saleOrder);
response.setValue("saleSupplySelect", product.getSaleSupplySelect());
response.setValues(saleOrderLine);
} catch (Exception e) {
resetProductInformation(response, saleOrderLine);
TraceBackService.trace(response, e);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.service.saleorder.SaleOrderLineService in project axelor-open-suite by axelor.
the class SaleOrderLineController method fillMaxDiscount.
/**
* Called from sale order line form view on load and on discount type select change. Call {@link
* SaleOrderLineService#computeMaxDiscount} and set the message to the view.
*
* @param request
* @param response
*/
public void fillMaxDiscount(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
BigDecimal maxDiscount = saleOrderLineService.computeMaxDiscount(saleOrder, saleOrderLine);
response.setValue("$maxDiscount", maxDiscount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations