use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method createShippingCostLine.
@Override
public PurchaseOrderLine createShippingCostLine(PurchaseOrder purchaseOrder, Product shippingCostProduct) throws AxelorException {
PurchaseOrderLine shippingCostLine = new PurchaseOrderLine();
shippingCostLine.setPurchaseOrder(purchaseOrder);
shippingCostLine.setProduct(shippingCostProduct);
purchaseOrderLineService.fill(shippingCostLine, purchaseOrder);
purchaseOrderLineService.compute(shippingCostLine, purchaseOrder);
return shippingCostLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method requestPurchaseOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void requestPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
super.requestPurchaseOrder(purchaseOrder);
return;
}
// budget control
if (appAccountService.isApp("budget") && appAccountService.getAppBudget().getCheckAvailableBudget()) {
List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
Map<Budget, BigDecimal> amountPerBudget = new HashMap<>();
if (appAccountService.getAppBudget().getManageMultiBudget()) {
for (PurchaseOrderLine pol : purchaseOrderLines) {
if (pol.getBudgetDistributionList() != null) {
for (BudgetDistribution bd : pol.getBudgetDistributionList()) {
Budget budget = bd.getBudget();
if (!amountPerBudget.containsKey(budget)) {
amountPerBudget.put(budget, bd.getAmount());
} else {
BigDecimal oldAmount = amountPerBudget.get(budget);
amountPerBudget.put(budget, oldAmount.add(bd.getAmount()));
}
isBudgetExceeded(budget, amountPerBudget.get(budget));
}
}
}
} else {
for (PurchaseOrderLine pol : purchaseOrderLines) {
// getting Budget associated to POL
Budget budget = pol.getBudget();
if (!amountPerBudget.containsKey(budget)) {
amountPerBudget.put(budget, pol.getExTaxTotal());
} else {
BigDecimal oldAmount = amountPerBudget.get(budget);
amountPerBudget.put(budget, oldAmount.add(pol.getExTaxTotal()));
}
isBudgetExceeded(budget, amountPerBudget.get(budget));
}
}
}
super.requestPurchaseOrder(purchaseOrder);
int intercoPurchaseCreatingStatus = Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseCreatingStatusSelect();
if (purchaseOrder.getInterco() && intercoPurchaseCreatingStatus == PurchaseOrderRepository.STATUS_REQUESTED) {
Beans.get(IntercoService.class).generateIntercoSaleFromPurchase(purchaseOrder);
}
if (purchaseOrder.getCreatedByInterco()) {
fillIntercompanySaleOrderCounterpart(purchaseOrder);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method createShipmentCostLine.
@Override
public String createShipmentCostLine(PurchaseOrder purchaseOrder) throws AxelorException {
List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
ShipmentMode shipmentMode = purchaseOrder.getShipmentMode();
if (shipmentMode == null) {
return null;
}
Product shippingCostProduct = shipmentMode.getShippingCostsProduct();
if (shipmentMode.getHasCarriagePaidPossibility()) {
BigDecimal carriagePaidThreshold = shipmentMode.getCarriagePaidThreshold();
if (computeExTaxTotalWithoutShippingLines(purchaseOrder).compareTo(carriagePaidThreshold) >= 0) {
String message = removeShipmentCostLine(purchaseOrder);
this.computePurchaseOrder(purchaseOrder);
return message;
}
}
if (alreadyHasShippingCostLine(purchaseOrder, shippingCostProduct)) {
return null;
}
PurchaseOrderLine shippingCostLine = createShippingCostLine(purchaseOrder, shippingCostProduct);
purchaseOrderLines.add(shippingCostLine);
this.computePurchaseOrder(purchaseOrder);
return null;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method createStockMove.
protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
List<Long> stockMoveIdList = new ArrayList<>();
Partner supplierPartner = purchaseOrder.getSupplierPartner();
Company company = purchaseOrder.getCompany();
Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
StockLocation startLocation = getStartStockLocation(purchaseOrder);
StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
stockMove.setOriginId(purchaseOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
stockMove.setTradingName(purchaseOrder.getTradingName());
stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
qualityStockMove.setOriginId(purchaseOrder.getId());
qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
qualityStockMove.setTradingName(purchaseOrder.getTradingName());
qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
} else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
}
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
}
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
stockMoveIdList.add(stockMove.getId());
}
if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(qualityStockMove);
stockMoveIdList.add(qualityStockMove.getId());
}
return stockMoveIdList;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method createInvoiceLines.
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<PurchaseOrderLine> purchaseOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
if (qtyToInvoiceMap.containsKey(purchaseOrderLine.getId())) {
List<InvoiceLine> invoiceLines = this.createInvoiceLine(invoice, purchaseOrderLine, qtyToInvoiceMap.get(purchaseOrderLine.getId()));
invoiceLineList.addAll(invoiceLines);
purchaseOrderLine.setInvoiced(true);
}
}
return invoiceLineList;
}
Aggregations