Search in sources :

Example 51 with SaleOrder

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

the class TestSaleOrderStockService method testUpdateDeliveryStatePartiallyDelivered2SaleOrder.

@Test
public void testUpdateDeliveryStatePartiallyDelivered2SaleOrder() throws AxelorException {
    SaleOrder saleOrder = new SaleOrder();
    SaleOrderLine saleOrderLine1 = new SaleOrderLine();
    SaleOrderLine saleOrderLine2 = new SaleOrderLine();
    saleOrderLine1.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_NOT_DELIVERED);
    saleOrderLine2.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_DELIVERED);
    saleOrder.addSaleOrderLineListItem(saleOrderLine1);
    saleOrder.addSaleOrderLineListItem(saleOrderLine2);
    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)

Example 52 with SaleOrder

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

the class SaleOrderLineSupplychainRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long saleOrderLineId = (Long) json.get("id");
    SaleOrderLine saleOrderLine = find(saleOrderLineId);
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (this.availabilityIsNotManaged(saleOrderLine, saleOrder)) {
        return super.populate(json, context);
    }
    BigDecimal availableStock = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getAvailableStock(saleOrder, saleOrderLine);
    BigDecimal allocatedStock = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getAllocatedStock(saleOrder, saleOrderLine);
    BigDecimal availableQty = availableStock.add(allocatedStock);
    BigDecimal realQty = saleOrderLine.getQty();
    if (availableQty.compareTo(realQty) >= 0) {
        saleOrderLine.setAvailableStatus(I18n.get("Available"));
        saleOrderLine.setAvailableStatusSelect(SaleOrderLineRepository.STATUS_AVAILABLE);
    } else if (availableQty.compareTo(realQty) < 0) {
        saleOrderLine.setAvailableStatus(I18n.get("Missing") + " (" + availableQty.subtract(realQty) + ")");
        saleOrderLine.setAvailableStatusSelect(SaleOrderLineRepository.STATUS_MISSING);
    }
    json.put("availableStatus", saleOrderLine.getAvailableStatus());
    json.put("availableStatusSelect", saleOrderLine.getAvailableStatusSelect());
    return super.populate(json, context);
}
Also used : SaleOrderLineServiceSupplyChainImpl(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChainImpl) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 53 with SaleOrder

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

the class ProjectBusinessServiceImpl method generateQuotation.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateQuotation(Project project) throws AxelorException {
    SaleOrder order = Beans.get(SaleOrderCreateService.class).createSaleOrder(project.getCompany());
    Partner clientPartner = project.getClientPartner();
    Partner contactPartner = project.getContactPartner();
    if (contactPartner == null && clientPartner.getContactPartnerSet().size() == 1) {
        contactPartner = clientPartner.getContactPartnerSet().iterator().next();
    }
    Company company = project.getCompany();
    order.setProject(projectRepo.find(project.getId()));
    order.setClientPartner(clientPartner);
    order.setContactPartner(contactPartner);
    order.setCompany(company);
    order.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
    order.setMainInvoicingAddressStr(addressService.computeAddressStr(order.getMainInvoicingAddress()));
    order.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
    order.setDeliveryAddressStr(addressService.computeAddressStr(order.getDeliveryAddress()));
    order.setIsNeedingConformityCertificate(clientPartner.getIsNeedingConformityCertificate());
    order.setCompanyBankDetails(Beans.get(AccountingSituationService.class).getCompanySalesBankDetails(company, clientPartner));
    if (project.getCurrency() != null) {
        order.setCurrency(project.getCurrency());
    } else if (clientPartner.getCurrency() != null) {
        order.setCurrency(clientPartner.getCurrency());
    } else {
        order.setCurrency(company.getCurrency());
    }
    if (project.getPriceList() != null) {
        order.setPriceList(project.getPriceList());
    } else {
        order.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE));
    }
    if (order.getPriceList() != null) {
        order.setHideDiscount(order.getPriceList().getHideDiscount());
    }
    if (clientPartner.getPaymentCondition() != null) {
        order.setPaymentCondition(clientPartner.getPaymentCondition());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentCondition(company.getAccountConfig().getDefPaymentCondition());
        }
    }
    if (clientPartner.getInPaymentMode() != null) {
        order.setPaymentMode(clientPartner.getInPaymentMode());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentMode(company.getAccountConfig().getInPaymentMode());
        }
    }
    AppSupplychain appSupplychain = Beans.get(AppSupplychainService.class).getAppSupplychain();
    if (appSupplychain != null) {
        order.setShipmentMode(clientPartner.getShipmentMode());
        order.setFreightCarrierMode(clientPartner.getFreightCarrierMode());
        if (clientPartner.getFreightCarrierMode() != null) {
            order.setCarrierPartner(clientPartner.getFreightCarrierMode().getCarrierPartner());
        }
        Boolean interco = appSupplychain.getIntercoFromSale() && !order.getCreatedByInterco() && clientPartner != null && Beans.get(CompanyRepository.class).all().filter("self.partner = ?", clientPartner).fetchOne() != null;
        order.setInterco(interco);
        // Automatic invoiced and delivered partners set in case of partner delegations
        if (appSupplychain.getActivatePartnerRelations()) {
            Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(order);
        }
    }
    return Beans.get(SaleOrderRepository.class).save(order);
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Transactional(com.google.inject.persist.Transactional)

Example 54 with SaleOrder

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

the class SaleOrderServiceSupplychainImpl method setDefaultInvoicedAndDeliveredPartners.

protected void setDefaultInvoicedAndDeliveredPartners(SaleOrder saleOrder, Partner clientPartner) {
    if (!CollectionUtils.isEmpty(clientPartner.getPartner1SupplychainLinkList())) {
        List<PartnerSupplychainLink> partnerSupplychainLinkList = clientPartner.getPartner1SupplychainLinkList();
        // Retrieve all Invoiced by Type
        List<PartnerSupplychainLink> partnerSupplychainLinkInvoicedByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
        // Retrieve all Delivered by Type
        List<PartnerSupplychainLink> partnerSupplychainLinkDeliveredByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_DELIVERED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
        // If there is only one, then it is the default one
        if (partnerSupplychainLinkInvoicedByList.size() == 1) {
            PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
            saleOrder.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
        } else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
            saleOrder.setInvoicedPartner(clientPartner);
        } else {
            saleOrder.setInvoicedPartner(null);
        }
        if (partnerSupplychainLinkDeliveredByList.size() == 1) {
            PartnerSupplychainLink partnerSupplychainLinkDeliveredBy = partnerSupplychainLinkDeliveredByList.get(0);
            saleOrder.setDeliveredPartner(partnerSupplychainLinkDeliveredBy.getPartner2());
        } else if (partnerSupplychainLinkDeliveredByList.size() == 0) {
            saleOrder.setDeliveredPartner(clientPartner);
        } else {
            saleOrder.setDeliveredPartner(null);
        }
    } else {
        saleOrder.setInvoicedPartner(clientPartner);
        saleOrder.setDeliveredPartner(clientPartner);
    }
}
Also used : IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PartnerService(com.axelor.apps.base.service.PartnerService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) StockMoveService(com.axelor.apps.stock.service.StockMoveService) AddressService(com.axelor.apps.base.service.AddressService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) AxelorException(com.axelor.exception.AxelorException) CollectionUtils(org.apache.commons.collections.CollectionUtils) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) CustomerShippingCarriagePaid(com.axelor.apps.supplychain.db.CustomerShippingCarriagePaid) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Timetable(com.axelor.apps.supplychain.db.Timetable) MethodHandles(java.lang.invoke.MethodHandles) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) MoreObjects(com.google.common.base.MoreObjects) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) ShipmentMode(com.axelor.apps.stock.db.ShipmentMode) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) SaleOrderServiceImpl(com.axelor.apps.sale.service.saleorder.SaleOrderServiceImpl) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Collections(java.util.Collections) PriceListRepository(com.axelor.apps.base.db.repo.PriceListRepository) SaleOrderMarginService(com.axelor.apps.sale.service.saleorder.SaleOrderMarginService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink)

Example 55 with SaleOrder

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

the class SaleOrderStockServiceImpl method createStocksMovesFromSaleOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public List<Long> createStocksMovesFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
    if (!this.isSaleOrderWithProductsToDeliver(saleOrder)) {
        return null;
    }
    if (saleOrder.getStockLocation() == null) {
        throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_MISSING_STOCK_LOCATION), saleOrder.getSaleOrderSeq());
    }
    List<Long> stockMoveList = new ArrayList<>();
    Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = getAllSaleOrderLinePerDate(saleOrder);
    for (LocalDate estimatedDeliveryDate : saleOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
        List<SaleOrderLine> saleOrderLineList = saleOrderLinePerDateMap.get(estimatedDeliveryDate);
        Optional<StockMove> stockMove = createStockMove(saleOrder, estimatedDeliveryDate, saleOrderLineList);
        stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
    }
    Optional<List<SaleOrderLine>> saleOrderLineList = Optional.ofNullable(saleOrderLinePerDateMap.get(null));
    if (saleOrderLineList.isPresent()) {
        Optional<StockMove> stockMove = createStockMove(saleOrder, null, saleOrderLineList.get());
        stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
    }
    return stockMoveList;
}
Also used : Company(com.axelor.apps.base.db.Company) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) Map(java.util.Map) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) RoundingMode(java.math.RoundingMode) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SupplyChainConfigRepository(com.axelor.apps.supplychain.db.repo.SupplyChainConfigRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(com.google.inject.persist.Transactional)

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