Search in sources :

Example 36 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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);
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) BlockingService(com.axelor.apps.base.service.BlockingService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 37 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method requestQty.

/**
 * Called from sale order line form view, on request qty click. Call {@link
 * ReservedQtyService#requestQty(SaleOrderLine)}
 *
 * @param request
 * @param response
 */
public void requestQty(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).requestQty(saleOrderLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 38 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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());
    }
}
Also used : StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) SaleOrderLineServiceSupplyChainImpl(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChainImpl) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 39 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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());
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Test(org.junit.Test)

Example 40 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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());
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Test(org.junit.Test)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6