use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method getSaleOrder.
@Override
public SaleOrder getSaleOrder(Context context) {
Context parentContext = context.getParent();
SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (parentContext != null && !parentContext.getContextClass().equals(SaleOrder.class)) {
parentContext = parentContext.getParent();
}
if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
saleOrder = parentContext.asType(SaleOrder.class);
}
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderServiceImpl method updateProductQtyWithPackHeaderQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder updateProductQtyWithPackHeaderQty(SaleOrder saleOrder) throws AxelorException {
List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
boolean isStartOfPack = false;
BigDecimal newQty = BigDecimal.ZERO;
BigDecimal oldQty = BigDecimal.ZERO;
this.sortSaleOrderLineList(saleOrder);
for (SaleOrderLine SOLine : saleOrderLineList) {
if (SOLine.getTypeSelect() == SaleOrderLineRepository.TYPE_START_OF_PACK && !isStartOfPack) {
newQty = SOLine.getQty();
oldQty = saleOrderLineRepo.find(SOLine.getId()).getQty();
if (newQty.compareTo(oldQty) != 0) {
isStartOfPack = true;
SOLine = EntityHelper.getEntity(SOLine);
saleOrderLineRepo.save(SOLine);
}
} else if (isStartOfPack) {
if (SOLine.getTypeSelect() == SaleOrderLineRepository.TYPE_END_OF_PACK) {
break;
}
saleOrderLineService.updateProductQty(SOLine, saleOrder, oldQty, newQty);
}
}
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderLineSaleRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
if (context.get("_model") != null && context.get("_model").toString().contains("SaleOrder") && context.get("id") != null) {
Long id = (Long) json.get("id");
if (id != null) {
SaleOrderLine saleOrderLine = find(id);
json.put("$hasWarning", saleOrderLine.getSaleOrder() != null && (saleOrderLine.getSaleOrder().getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION || (saleOrderLine.getSaleOrder().getStatusSelect() == SaleOrderRepository.STATUS_ORDER_CONFIRMED && saleOrderLine.getSaleOrder().getOrderBeingEdited())) && saleOrderLine.getDiscountsNeedReview());
}
}
return super.populate(json, context);
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderLineController method cancelReservation.
/**
* Called from sale order line form view, on request qty click. Call {@link
* ReservedQtyService#cancelReservation(SaleOrderLine)}
*
* @param request
* @param response
*/
public void cancelReservation(ActionRequest request, ActionResponse response) {
try {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
Product product = saleOrderLine.getProduct();
if (product == null || !product.getStockManaged()) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
}
Beans.get(ReservedQtyService.class).cancelReservation(saleOrderLine);
response.setReload(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 SaleOrderLineController method supplierPartnerDefault.
/**
* Called from sale order line form, on product change and on sale supply select change
*
* @param request
* @param response
*/
public void supplierPartnerDefault(ActionRequest request, ActionResponse response) {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_PURCHASE) {
return;
}
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (saleOrder == null) {
Context parentContext = request.getContext().getParent();
if (parentContext == null) {
return;
}
saleOrder = parentContext.asType(SaleOrder.class);
}
if (saleOrder == null) {
return;
}
Partner supplierPartner = null;
if (saleOrderLine.getProduct() != null) {
supplierPartner = saleOrderLine.getProduct().getDefaultSupplierPartner();
}
if (supplierPartner != null) {
Blocking blocking = Beans.get(BlockingService.class).getBlocking(supplierPartner, saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
if (blocking != null) {
supplierPartner = null;
}
}
response.setValue("supplierPartner", supplierPartner);
}
Aggregations