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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations