use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class WorkflowCancelServiceSupplychainImpl method purchaseOrderLineProcess.
public PurchaseOrder purchaseOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
if (purchaseOrderLine == null) {
return null;
}
PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
// If is it a refund invoice, so we negate the amount invoiced
if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
invoicedAmountToAdd = invoicedAmountToAdd.negate();
}
// Update invoiced amount on purchase order line
if (!invoice.getCurrency().equals(purchaseOrder.getCurrency()) && purchaseOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
// If the purchase order currency is different from the invoice currency, use company currency
// to calculate a rate. This rate will be applied to purchase order line
BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
BigDecimal rate = currentCompanyInvoicedAmount.divide(purchaseOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
invoicedAmountToAdd = rate.multiply(purchaseOrderLine.getExTaxTotal());
}
purchaseOrderLine.setAmountInvoiced(purchaseOrderLine.getAmountInvoiced().subtract(invoicedAmountToAdd));
return purchaseOrder;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method updatePurchaseOrderLines.
protected void updatePurchaseOrderLines(StockMove stockMove, boolean qtyWasReceived) throws AxelorException {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
if (stockMoveLine.getPurchaseOrderLine() != null) {
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
if (qtyWasReceived) {
purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().add(realQty));
} else {
purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().subtract(realQty));
}
if (purchaseOrderLine.getReceivedQty().signum() == 0) {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
} else if (purchaseOrderLine.getReceivedQty().compareTo(purchaseOrderLine.getQty()) < 0) {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
} else {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_RECEIVED);
}
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoSaleFromPurchase.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
// create sale order
SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
// in ati
saleOrder.setInAti(purchaseOrder.getInAti());
// copy date
saleOrder.setOrderDate(purchaseOrder.getOrderDate());
// copy payments
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
saleOrder.setPaymentMode(intercoPaymentMode);
saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
// copy delivery info
saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
// get stock location
saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
// copy timetable info
saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
// create lines
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLineList != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
}
}
saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
// compute the sale order
saleOrderComputeService.computeSaleOrder(saleOrder);
saleOrder.setCreatedByInterco(true);
Beans.get(SaleOrderRepository.class).save(saleOrder);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
}
purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
return saleOrder;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoPurchaseLineFromSaleLine.
/**
* @param saleOrderLine the sale order line needed to create the purchase order line
* @param purchaseOrder the purchase order line belongs to this purchase order
* @return the created purchase order line
*/
protected PurchaseOrderLine createIntercoPurchaseLineFromSaleLine(SaleOrderLine saleOrderLine, PurchaseOrder purchaseOrder) throws AxelorException {
PurchaseOrderLine purchaseOrderLine = Beans.get(PurchaseOrderLineService.class).createPurchaseOrderLine(purchaseOrder, saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), saleOrderLine.getQty(), saleOrderLine.getUnit());
// compute amount
purchaseOrderLine.setPrice(saleOrderLine.getPrice());
purchaseOrderLine.setInTaxPrice(saleOrderLine.getInTaxPrice());
purchaseOrderLine.setExTaxTotal(saleOrderLine.getExTaxTotal());
purchaseOrderLine.setDiscountTypeSelect(saleOrderLine.getDiscountTypeSelect());
purchaseOrderLine.setDiscountAmount(saleOrderLine.getDiscountAmount());
// delivery
purchaseOrderLine.setEstimatedDelivDate(saleOrderLine.getEstimatedDelivDate());
// compute price discounted
BigDecimal priceDiscounted = Beans.get(PurchaseOrderLineService.class).computeDiscount(purchaseOrderLine, purchaseOrder.getInAti());
purchaseOrderLine.setPriceDiscounted(priceDiscounted);
// tax
purchaseOrderLine.setTaxLine(saleOrderLine.getTaxLine());
// analyticalDistribution
purchaseOrderLine = Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).getAndComputeAnalyticDistribution(purchaseOrderLine, purchaseOrder);
purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
return purchaseOrderLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class InvoiceLineSupplychainService method computeBudgetDistributionSumAmount.
public void computeBudgetDistributionSumAmount(InvoiceLine invoiceLine, Invoice invoice) {
List<BudgetDistribution> budgetDistributionList = invoiceLine.getBudgetDistributionList();
PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
BigDecimal budgetDistributionSumAmount = BigDecimal.ZERO;
LocalDate computeDate = invoice.getInvoiceDate();
if (purchaseOrderLine != null && purchaseOrderLine.getPurchaseOrder().getOrderDate() != null) {
computeDate = purchaseOrderLine.getPurchaseOrder().getOrderDate();
}
if (budgetDistributionList != null && !budgetDistributionList.isEmpty()) {
for (BudgetDistribution budgetDistribution : budgetDistributionList) {
budgetDistributionSumAmount = budgetDistributionSumAmount.add(budgetDistribution.getAmount());
Beans.get(BudgetSupplychainService.class).computeBudgetDistributionSumAmount(budgetDistribution, computeDate);
}
}
invoiceLine.setBudgetDistributionSumAmount(budgetDistributionSumAmount);
}
Aggregations