Search in sources :

Example 1 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class ManufOrderWorkflowService method createPurchaseOrder.

@Transactional
public void createPurchaseOrder(ManufOrder manufOrder) throws AxelorException {
    PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderService.class).createPurchaseOrder(null, manufOrder.getCompany(), null, null, null, null, null, null, null, manufOrder.getProdProcess().getSubcontractors(), null);
    purchaseOrder.setOutsourcingOrder(true);
    if (manufOrder.getCompany() != null && manufOrder.getCompany().getStockConfig() != null) {
        purchaseOrder.setStockLocation(manufOrder.getCompany().getStockConfig().getOutsourcingReceiptStockLocation());
    }
    this.setPurchaseOrderSupplierDetails(purchaseOrder);
    for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
        if (operationOrder.getUseLineInGeneratedPurchaseOrder()) {
            this.createPurchaseOrderLineProduction(operationOrder, purchaseOrder);
        }
    }
    Beans.get(PurchaseOrderService.class).computePurchaseOrder(purchaseOrder);
    manufOrder.setPurchaseOrder(purchaseOrder);
    manufOrderRepo.save(manufOrder);
}
Also used : PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 2 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class SaleOrderPurchaseServiceImpl method createPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder createPurchaseOrder(Partner supplierPartner, List<SaleOrderLine> saleOrderLineList, SaleOrder saleOrder) throws AxelorException {
    LOG.debug("Création d'une commande fournisseur pour le devis client : {}", saleOrder.getSaleOrderSeq());
    PurchaseOrder purchaseOrder = purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), saleOrder.getCompany(), supplierPartner.getContactPartnerSet().size() == 1 ? supplierPartner.getContactPartnerSet().iterator().next() : null, supplierPartner.getCurrency(), null, saleOrder.getSaleOrderSeq(), saleOrder.getExternalReference(), saleOrder.getDirectOrderLocation() ? saleOrder.getStockLocation() : Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(saleOrder.getCompany()), Beans.get(AppBaseService.class).getTodayDate(saleOrder.getCompany()), Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, saleOrder.getTradingName());
    purchaseOrder.setGeneratedSaleOrderId(saleOrder.getId());
    purchaseOrder.setGroupProductsOnPrintings(supplierPartner.getGroupProductsOnPrintings());
    Integer atiChoice = Beans.get(PurchaseConfigService.class).getPurchaseConfig(saleOrder.getCompany()).getPurchaseOrderInAtiSelect();
    if (atiChoice == AccountConfigRepository.INVOICE_ATI_ALWAYS || atiChoice == AccountConfigRepository.INVOICE_ATI_DEFAULT) {
        purchaseOrder.setInAti(true);
    } else {
        purchaseOrder.setInAti(false);
    }
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLineServiceSupplychain.createPurchaseOrderLine(purchaseOrder, saleOrderLine));
    }
    purchaseOrderService.computePurchaseOrder(purchaseOrder);
    purchaseOrder.setNotes(supplierPartner.getPurchaseOrderComments());
    Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
    return purchaseOrder;
}
Also used : StockLocationService(com.axelor.apps.stock.service.StockLocationService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) Transactional(com.google.inject.persist.Transactional)

Example 3 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method needControlOnReceipt.

/**
 * @param product
 * @param purchaseOrder
 * @return true if product needs a control on receipt and if the purchase order is not a direct
 *     order
 */
protected boolean needControlOnReceipt(PurchaseOrderLine purchaseOrderLine) {
    Product product = purchaseOrderLine.getProduct();
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    if (product.getControlOnReceipt() && !purchaseOrder.getStockLocation().getDirectOrderLocation()) {
        return true;
    }
    return false;
}
Also used : Product(com.axelor.apps.base.db.Product) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 4 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createProductStockMoveLine.

protected StockMoveLine createProductStockMoveLine(PurchaseOrderLine purchaseOrderLine, BigDecimal qty, StockMove stockMove) throws AxelorException {
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    Product product = purchaseOrderLine.getProduct();
    Unit unit = product.getUnit();
    BigDecimal priceDiscounted = purchaseOrderLine.getPriceDiscounted();
    BigDecimal companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal();
    if (purchaseOrderLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
        companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal().divide(purchaseOrderLine.getQty(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    }
    if (unit != null && !unit.equals(purchaseOrderLine.getUnit())) {
        qty = unitConversionService.convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), product);
        priceDiscounted = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        companyUnitPriceUntaxed = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), companyUnitPriceUntaxed, appBaseService.getNbDecimalDigitForUnitPrice(), product);
    }
    BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), qty);
    BigDecimal companyPurchasePrice = priceDiscounted;
    priceDiscounted = priceDiscounted.multiply(shippingCoef);
    companyUnitPriceUntaxed = companyUnitPriceUntaxed.multiply(shippingCoef);
    BigDecimal taxRate = BigDecimal.ZERO;
    TaxLine taxLine = purchaseOrderLine.getTaxLine();
    if (taxLine != null) {
        taxRate = taxLine.getValue();
    }
    if (purchaseOrderLine.getReceiptState() == 0) {
        purchaseOrderLine.setReceiptState(PurchaseOrderLineRepository.RECEIPT_STATE_NOT_RECEIVED);
    }
    return stockMoveLineServiceSupplychain.createStockMoveLine(product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qty, BigDecimal.ZERO, priceDiscounted, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, StockMoveLineService.TYPE_PURCHASES, purchaseOrder.getInAti(), taxRate, null, purchaseOrderLine);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 5 with PurchaseOrder

use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createStockMoveFromPurchaseOrder.

/**
 * Méthode permettant de créer un StockMove à partir d'un PurchaseOrder.
 *
 * @param purchaseOrder une commande
 * @throws AxelorException Aucune séquence de StockMove n'a été configurée
 */
public List<Long> createStockMoveFromPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    if (purchaseOrder.getPurchaseOrderLineList() == null || purchaseOrder.getCompany() == null) {
        return stockMoveIdList;
    }
    if (purchaseOrder.getStockLocation() == null) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PO_MISSING_STOCK_LOCATION), purchaseOrder.getPurchaseOrderSeq());
    }
    Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = getAllPurchaseOrderLinePerDate(purchaseOrder);
    for (LocalDate estimatedDeliveryDate : purchaseOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
        List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLinePerDateMap.get(estimatedDeliveryDate);
        List<Long> stockMoveId = createStockMove(purchaseOrder, estimatedDeliveryDate, purchaseOrderLineList);
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    Optional<List<PurchaseOrderLine>> purchaseOrderLineListDeliveryDateNull = Optional.ofNullable(purchaseOrderLinePerDateMap.get(null));
    if (purchaseOrderLineListDeliveryDateNull.isPresent()) {
        List<Long> stockMoveId = createStockMove(purchaseOrder, null, purchaseOrderLineListDeliveryDateNull.get());
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    return stockMoveIdList;
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Map(java.util.Map) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) List(java.util.List) Product(com.axelor.apps.base.db.Product) PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Company(com.axelor.apps.base.db.Company) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) SupplyChainConfigRepository(com.axelor.apps.supplychain.db.repo.SupplyChainConfigRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Aggregations

PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)84 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)26 AxelorException (com.axelor.exception.AxelorException)26 Transactional (com.google.inject.persist.Transactional)16 BigDecimal (java.math.BigDecimal)12 Company (com.axelor.apps.base.db.Company)11 Context (com.axelor.rpc.Context)10 Partner (com.axelor.apps.base.db.Partner)9 Product (com.axelor.apps.base.db.Product)9 ArrayList (java.util.ArrayList)9 Invoice (com.axelor.apps.account.db.Invoice)7 List (java.util.List)7 PurchaseOrderRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)6 SaleOrder (com.axelor.apps.sale.db.SaleOrder)6 PurchaseOrderSupplychainService (com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService)6 LocalDate (java.time.LocalDate)6 PurchaseOrderService (com.axelor.apps.purchase.service.PurchaseOrderService)5 StockMove (com.axelor.apps.stock.db.StockMove)5 Unit (com.axelor.apps.base.db.Unit)4 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)4