use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceSupplychainImpl method createPurchaseOrderLine.
public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder, SaleOrderLine saleOrderLine) throws AxelorException {
LOG.debug("Création d'une ligne de commande fournisseur pour le produit : {}", saleOrderLine.getProductName());
Unit unit = null;
BigDecimal qty = BigDecimal.ZERO;
if (saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL) {
if (saleOrderLine.getProduct() != null) {
unit = saleOrderLine.getProduct().getPurchasesUnit();
}
qty = saleOrderLine.getQty();
if (unit == null) {
unit = saleOrderLine.getUnit();
} else {
qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
}
}
PurchaseOrderLine purchaseOrderLine = super.createPurchaseOrderLine(purchaseOrder, saleOrderLine.getProduct(), saleOrderLine.getProductName(), null, qty, unit);
purchaseOrderLine.setIsTitleLine(!(saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL));
this.getAndComputeAnalyticDistribution(purchaseOrderLine, purchaseOrder);
return purchaseOrderLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method removeShipmentCostLine.
@Override
@Transactional(rollbackOn = Exception.class)
public String removeShipmentCostLine(PurchaseOrder purchaseOrder) {
List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLines == null) {
return null;
}
List<PurchaseOrderLine> linesToRemove = new ArrayList<PurchaseOrderLine>();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLines) {
if (purchaseOrderLine.getProduct().getIsShippingCostsProduct()) {
linesToRemove.add(purchaseOrderLine);
}
}
if (linesToRemove.size() == 0) {
return null;
}
for (PurchaseOrderLine lineToRemove : linesToRemove) {
purchaseOrderLines.remove(lineToRemove);
if (lineToRemove.getId() != null) {
purchaseOrderLineRepository.remove(lineToRemove);
}
}
purchaseOrder.setPurchaseOrderLineList(purchaseOrderLines);
return I18n.get("Carriage paid threshold is exceeded, all shipment cost lines are removed");
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method applyToallBudgetDistribution.
@Transactional
@Override
public void applyToallBudgetDistribution(PurchaseOrder purchaseOrder) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
BudgetDistribution newBudgetDistribution = new BudgetDistribution();
newBudgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal());
newBudgetDistribution.setBudget(purchaseOrder.getBudget());
newBudgetDistribution.setPurchaseOrderLine(purchaseOrderLine);
Beans.get(BudgetDistributionRepository.class).save(newBudgetDistribution);
Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrder);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method getAllPurchaseOrderLinePerDate.
protected Map<LocalDate, List<PurchaseOrderLine>> getAllPurchaseOrderLinePerDate(PurchaseOrder purchaseOrder) {
Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = new HashMap<>();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
if (purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine).signum() <= 0) {
continue;
}
LocalDate dateKey = purchaseOrderLine.getEstimatedDelivDate();
if (dateKey == null) {
dateKey = purchaseOrderLine.getPurchaseOrder().getDeliveryDate();
}
List<PurchaseOrderLine> purchaseOrderLineLists = purchaseOrderLinePerDateMap.get(dateKey);
if (purchaseOrderLineLists == null) {
purchaseOrderLineLists = new ArrayList<>();
purchaseOrderLinePerDateMap.put(dateKey, purchaseOrderLineLists);
}
purchaseOrderLineLists.add(purchaseOrderLine);
}
return purchaseOrderLinePerDateMap;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine 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