Search in sources :

Example 1 with PartnerSupplychainLink

use of com.axelor.apps.supplychain.db.PartnerSupplychainLink 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 2 with PartnerSupplychainLink

use of com.axelor.apps.supplychain.db.PartnerSupplychainLink in project axelor-open-suite by axelor.

the class StockMoveServiceSupplychainImpl method setDefaultInvoicedPartner.

@Override
public void setDefaultInvoicedPartner(StockMove stockMove) {
    if (stockMove != null && stockMove.getPartner() != null && stockMove.getPartner().getId() != null) {
        Partner partner = Beans.get(PartnerRepository.class).find(stockMove.getPartner().getId());
        if (partner != null) {
            if (!CollectionUtils.isEmpty(partner.getPartner1SupplychainLinkList())) {
                List<PartnerSupplychainLink> partnerSupplychainLinkList = partner.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());
                // If there is only one, then it is the default one
                if (partnerSupplychainLinkInvoicedByList.size() == 1) {
                    PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
                    stockMove.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
                } else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
                    stockMove.setInvoicedPartner(partner);
                } else {
                    stockMove.setInvoicedPartner(null);
                }
            } else {
                stockMove.setInvoicedPartner(partner);
            }
        }
    }
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) PartnerProductQualityRatingService(com.axelor.apps.stock.service.PartnerProductQualityRatingService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Transactional(com.google.inject.persist.Transactional) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) StockMoveServiceImpl(com.axelor.apps.stock.service.StockMoveServiceImpl) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) JPA(com.axelor.db.JPA) 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) MethodHandles(java.lang.invoke.MethodHandles) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Query(javax.persistence.Query) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) StringJoiner(java.util.StringJoiner) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) Partner(com.axelor.apps.base.db.Partner)

Aggregations

AppSupplychain (com.axelor.apps.base.db.AppSupplychain)2 Partner (com.axelor.apps.base.db.Partner)2 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)2 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)2 StockMove (com.axelor.apps.stock.db.StockMove)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)2 PartnerSupplychainLink (com.axelor.apps.supplychain.db.PartnerSupplychainLink)2 PartnerSupplychainLinkTypeRepository (com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository)2 IExceptionMessage (com.axelor.apps.supplychain.exception.IExceptionMessage)2 AppSupplychainService (com.axelor.apps.supplychain.service.app.AppSupplychainService)2 AxelorException (com.axelor.exception.AxelorException)2 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)2 I18n (com.axelor.i18n.I18n)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2