Search in sources :

Example 46 with SaleOrder

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);
    }
}
Also used : PartnerSupplychainLinkService(com.axelor.apps.supplychain.service.PartnerSupplychainLinkService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 47 with SaleOrder

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);
}
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 48 with SaleOrder

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());
    }
}
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 49 with SaleOrder

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

Example 50 with SaleOrder

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

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)129 AxelorException (com.axelor.exception.AxelorException)53 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)35 BigDecimal (java.math.BigDecimal)24 Context (com.axelor.rpc.Context)20 Transactional (com.google.inject.persist.Transactional)19 ArrayList (java.util.ArrayList)19 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)18 Company (com.axelor.apps.base.db.Company)16 Partner (com.axelor.apps.base.db.Partner)15 IOException (java.io.IOException)13 BirtException (org.eclipse.birt.core.exception.BirtException)13 Invoice (com.axelor.apps.account.db.Invoice)12 List (java.util.List)12 Currency (com.axelor.apps.base.db.Currency)11 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 Product (com.axelor.apps.base.db.Product)8 StockMove (com.axelor.apps.stock.db.StockMove)8