Search in sources :

Example 31 with SaleOrder

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

the class SaleOrderCreateServiceImpl method createSaleOrder.

@Override
public SaleOrder createSaleOrder(User salespersonUser, Company company, Partner contactPartner, Currency currency, LocalDate deliveryDate, String internalReference, String externalReference, PriceList priceList, Partner clientPartner, Team team, TradingName tradingName) throws AxelorException {
    logger.debug("Création d'un devis client : Société = {},  Reference externe = {}, Client = {}", company, externalReference, clientPartner.getFullName());
    SaleOrder saleOrder = new SaleOrder();
    saleOrder.setClientPartner(clientPartner);
    saleOrder.setCreationDate(appSaleService.getTodayDate(company));
    saleOrder.setContactPartner(contactPartner);
    saleOrder.setCurrency(currency);
    saleOrder.setExternalReference(externalReference);
    saleOrder.setDeliveryDate(deliveryDate);
    saleOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(tradingName, company));
    if (salespersonUser == null) {
        salespersonUser = AuthUtils.getUser();
    }
    saleOrder.setSalespersonUser(salespersonUser);
    if (team == null) {
        team = salespersonUser.getActiveTeam();
    }
    saleOrder.setTeam(team);
    if (company == null) {
        company = salespersonUser.getActiveCompany();
    }
    saleOrder.setCompany(company);
    saleOrder.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
    saleOrder.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
    saleOrderService.computeAddressStr(saleOrder);
    if (priceList == null) {
        priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE);
    }
    saleOrder.setPriceList(priceList);
    saleOrder.setSaleOrderLineList(new ArrayList<>());
    saleOrder.setStatusSelect(SaleOrderRepository.STATUS_DRAFT_QUOTATION);
    saleOrderService.computeEndOfValidityDate(saleOrder);
    return saleOrder;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 32 with SaleOrder

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

the class SaleOrderCreateServiceImpl method mergeSaleOrders.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder mergeSaleOrders(List<SaleOrder> saleOrderList, Currency currency, Partner clientPartner, Company company, Partner contactPartner, PriceList priceList, Team team) throws AxelorException {
    String numSeq = "";
    String externalRef = "";
    for (SaleOrder saleOrderLocal : saleOrderList) {
        if (!numSeq.isEmpty()) {
            numSeq += "-";
        }
        numSeq += saleOrderLocal.getSaleOrderSeq();
        if (!externalRef.isEmpty()) {
            externalRef += "|";
        }
        if (saleOrderLocal.getExternalReference() != null) {
            externalRef += saleOrderLocal.getExternalReference();
        }
    }
    SaleOrder saleOrderMerged = this.createSaleOrder(AuthUtils.getUser(), company, contactPartner, currency, null, numSeq, externalRef, priceList, clientPartner, team);
    this.attachToNewSaleOrder(saleOrderList, saleOrderMerged);
    saleOrderComputeService.computeSaleOrder(saleOrderMerged);
    saleOrderRepo.save(saleOrderMerged);
    this.removeOldSaleOrders(saleOrderList);
    return saleOrderMerged;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Example 33 with SaleOrder

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

the class SaleOrderCreateServiceImpl method attachToNewSaleOrder.

// Attachment of all sale order lines to new sale order
protected void attachToNewSaleOrder(List<SaleOrder> saleOrderList, SaleOrder saleOrderMerged) {
    for (SaleOrder saleOrder : saleOrderList) {
        int countLine = 1;
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            saleOrderLine.setSequence(countLine * 10);
            saleOrderMerged.addSaleOrderLineListItem(saleOrderLine);
            countLine++;
        }
    }
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 34 with SaleOrder

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

the class SaleOrderLineServiceImpl method manageComplementaryProductSaleOrderLine.

@Override
public List<SaleOrderLine> manageComplementaryProductSaleOrderLine(SaleOrderLine saleOrderLine, SaleOrder saleOrder, List<ComplementaryProduct> complementaryProducts) throws AxelorException {
    List<SaleOrderLine> newComplementarySOLines = new ArrayList<>();
    if (saleOrderLine.getComplementarySaleOrderLineList() == null) {
        saleOrderLine.setComplementarySaleOrderLineList(new ArrayList<>());
    }
    for (ComplementaryProduct complementaryProduct : complementaryProducts) {
        Product product = complementaryProduct.getProduct();
        if (product == null) {
            continue;
        }
        SaleOrderLine complementarySOLine;
        Optional<SaleOrderLine> complementarySOLineOpt = saleOrderLine.getComplementarySaleOrderLineList().stream().filter(line -> line.getMainSaleOrderLine() != null && line.getProduct().equals(product)).findFirst();
        if (complementarySOLineOpt.isPresent()) {
            complementarySOLine = complementarySOLineOpt.get();
        } else {
            complementarySOLine = new SaleOrderLine();
            complementarySOLine.setSequence(saleOrderLine.getSequence());
            complementarySOLine.setProduct(complementaryProduct.getProduct());
            saleOrderLine.addComplementarySaleOrderLineListItem(complementarySOLine);
            newComplementarySOLines.add(complementarySOLine);
        }
        complementarySOLine.setQty(complementaryProduct.getQty());
        this.computeProductInformation(complementarySOLine, saleOrder);
        this.computeValues(saleOrder, complementarySOLine);
        saleOrderLineRepo.save(complementarySOLine);
    }
    return newComplementarySOLines;
}
Also used : Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PriceListService(com.axelor.apps.base.service.PriceListService) HashMap(java.util.HashMap) CurrencyService(com.axelor.apps.base.service.CurrencyService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) ArrayList(java.util.ArrayList) PriceListLine(com.axelor.apps.base.db.PriceListLine) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PackLineRepository(com.axelor.apps.sale.db.repo.PackLineRepository) PriceListLineRepository(com.axelor.apps.base.db.repo.PriceListLineRepository) RoundingMode(java.math.RoundingMode) ITranslation(com.axelor.apps.sale.translation.ITranslation) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) AppSaleService(com.axelor.apps.sale.service.app.AppSaleService) Logger(org.slf4j.Logger) ProductCategoryService(com.axelor.apps.base.service.ProductCategoryService) MethodHandles(java.lang.invoke.MethodHandles) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) PackLine(com.axelor.apps.sale.db.PackLine) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) Pack(com.axelor.apps.sale.db.Pack) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) ModuleManager(com.axelor.meta.loader.ModuleManager) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) ComplementaryProductSelected(com.axelor.apps.sale.db.ComplementaryProductSelected) ObjectUtils(com.axelor.common.ObjectUtils) PriceList(com.axelor.apps.base.db.PriceList) ProductMultipleQtyService(com.axelor.apps.base.service.ProductMultipleQtyService) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) Optional(java.util.Optional) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) Context(com.axelor.rpc.Context) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 35 with SaleOrder

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

the class SaleOrderLineServiceImpl method getSaleOrder.

@Override
public SaleOrder getSaleOrder(Context context) {
    Context parentContext = context.getParent();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (parentContext != null && !parentContext.getContextClass().equals(SaleOrder.class)) {
        parentContext = parentContext.getParent();
    }
    if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
        saleOrder = parentContext.asType(SaleOrder.class);
    }
    return saleOrder;
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

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