use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderController method setInvoicedPartnerDomain.
/**
* Called from sale order form view, on invoiced partner select. Call {@link
* PartnerSupplychainLinkService#computePartnerFilter}
*
* @param request
* @param response
*/
public void setInvoicedPartnerDomain(ActionRequest request, ActionResponse response) {
try {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
String strFilter = Beans.get(PartnerSupplychainLinkService.class).computePartnerFilter(saleOrder.getClientPartner(), PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY);
response.setAttr("invoicedPartner", "domain", strFilter);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineController method supplierPartnerDomain.
/**
* Called from sale order line form. Set domain for supplier partner.
*
* @param request
* @param response
*/
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
String domain = "self.isContact = false AND self.isSupplier = true";
Product product = saleOrderLine.getProduct();
if (product != null) {
List<Long> authorizedPartnerIdsList = Beans.get(SaleOrderLineServiceSupplyChain.class).getSupplierPartnerList(saleOrderLine);
if (authorizedPartnerIdsList.isEmpty()) {
response.setAttr("supplierPartner", "domain", "self.id IN (0)");
return;
} else {
domain += String.format(" AND self.id IN (%s)", authorizedPartnerIdsList.stream().map(Object::toString).collect(Collectors.joining(",")));
}
}
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
if (saleOrder == null) {
Context parentContext = request.getContext().getParent();
if (parentContext == null) {
response.setAttr("supplierPartner", "domain", domain);
return;
}
saleOrder = parentContext.asType(SaleOrder.class);
if (saleOrder == null) {
response.setAttr("supplierPartner", "domain", domain);
return;
}
}
String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
}
if (saleOrder.getCompany() != null) {
domain += " AND " + saleOrder.getCompany().getId() + " in (SELECT id FROM self.companySet)";
}
response.setAttr("supplierPartner", "domain", domain);
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class SaleOrderLineController method checkStocks.
public void checkStocks(ActionRequest request, ActionResponse response) {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
SaleOrder saleOrder = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getSaleOrder(request.getContext());
if (saleOrder.getStockLocation() == null) {
return;
}
try {
if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_FROM_STOCK) {
return;
}
// Use the unit to get the right quantity
Unit unit = null;
if (saleOrderLine.getProduct() != null)
unit = saleOrderLine.getProduct().getUnit();
BigDecimal qty = saleOrderLine.getQty();
if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
qty = Beans.get(UnitConversionService.class).convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
}
Beans.get(StockLocationLineService.class).checkIfEnoughStock(saleOrder.getStockLocation(), saleOrderLine.getProduct(), qty);
} catch (Exception e) {
response.setAlert(e.getLocalizedMessage());
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class TestSaleOrderStockService method testUpdateDeliveryStateDeliveredSaleOrder.
@Test
public void testUpdateDeliveryStateDeliveredSaleOrder() throws AxelorException {
SaleOrder saleOrder = new SaleOrder();
saleOrder.setSaleOrderLineList(new ArrayList<>());
SaleOrderLine saleOrderLine1 = new SaleOrderLine();
SaleOrderLine saleOrderLine2 = new SaleOrderLine();
saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
saleOrder.addSaleOrderLineListItem(saleOrderLine1);
saleOrder.addSaleOrderLineListItem(saleOrderLine2);
saleOrderStockService.updateDeliveryState(saleOrder);
Assert.assertEquals(SaleOrderRepository.DELIVERY_STATE_DELIVERED, (int) saleOrder.getDeliveryState());
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class TestSaleOrderStockService method testUpdateDeliveryStateOnlyPartiallyDeliveredLinesSaleOrder.
@Test
public void testUpdateDeliveryStateOnlyPartiallyDeliveredLinesSaleOrder() throws AxelorException {
SaleOrder saleOrder = new SaleOrder();
saleOrder.setSaleOrderLineList(new ArrayList<>());
SaleOrderLine saleOrderLine1 = new SaleOrderLine();
SaleOrderLine saleOrderLine2 = new SaleOrderLine();
SaleOrderLine saleOrderLine3 = new SaleOrderLine();
saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_NOT_DELIVERED);
saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
saleOrderLine3.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
saleOrder.addSaleOrderLineListItem(saleOrderLine1);
saleOrder.addSaleOrderLineListItem(saleOrderLine2);
saleOrder.addSaleOrderLineListItem(saleOrderLine3);
saleOrderStockService.updateDeliveryState(saleOrder);
Assert.assertEquals(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED, (int) saleOrder.getDeliveryState());
}
Aggregations