use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class WorkflowVentilationServiceSupplychainImpl method purchaseOrderLineProcess.
private 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().add(invoicedAmountToAdd));
return purchaseOrder;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class ImportPurchaseOrderLine method importPurchaseOrderLine.
public Object importPurchaseOrderLine(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof PurchaseOrderLine;
PurchaseOrderLine purchaseOrderLine = (PurchaseOrderLine) bean;
PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrderLine.getPurchaseOrder());
return purchaseOrderLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class ABCAnalysisServicePurchaseImpl method createABCAnalysisLine.
@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
ABCAnalysisLine abcAnalysisLine = null;
BigDecimal productQty = BigDecimal.ZERO;
BigDecimal productWorth = BigDecimal.ZERO;
List<PurchaseOrderLine> purchaseOrderLineList;
int offset = 0;
Query<PurchaseOrderLine> purchaseOrderLineQuery = purchaseOrderLineRepository.all().filter("(self.purchaseOrder.statusSelect = :statusValidated OR self.purchaseOrder.statusSelect = :statusFinished) AND self.purchaseOrder.validationDate >= :startDate AND self.purchaseOrder.validationDate <= :endDate AND self.product.id = :productId").bind("statusValidated", PurchaseOrderRepository.STATUS_VALIDATED).bind("statusFinished", PurchaseOrderRepository.STATUS_FINISHED).bind("startDate", abcAnalysis.getStartDate()).bind("endDate", abcAnalysis.getEndDate()).bind("productId", product.getId()).order("id");
while (!(purchaseOrderLineList = purchaseOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += purchaseOrderLineList.size();
abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
if (abcAnalysisLine == null) {
abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
}
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
BigDecimal convertedQty = unitConversionService.convert(purchaseOrderLine.getUnit(), product.getUnit(), purchaseOrderLine.getQty(), 2, product);
productQty = productQty.add(convertedQty);
productWorth = productWorth.add(purchaseOrderLine.getCompanyExTaxTotal());
}
super.incTotalQty(productQty);
super.incTotalWorth(productWorth);
JPA.clear();
}
if (abcAnalysisLine != null) {
setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
}
return Optional.ofNullable(abcAnalysisLine);
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method createPurchaseOrderLine.
@Override
public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder, Product product, String productName, String description, BigDecimal qty, Unit unit) throws AxelorException {
PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
purchaseOrderLine.setPurchaseOrder(purchaseOrder);
purchaseOrderLine.setEstimatedDelivDate(purchaseOrder.getDeliveryDate());
if (product != null) {
purchaseOrderLine.setProduct(product);
fill(purchaseOrderLine, purchaseOrder);
}
if (description != null) {
purchaseOrderLine.setDescription(description);
}
purchaseOrderLine.setIsOrdered(false);
if (qty != null) {
purchaseOrderLine.setQty(qty);
}
purchaseOrderLine.setSequence(sequence);
sequence++;
if (unit != null) {
purchaseOrderLine.setUnit(unit);
}
if (productName != null) {
purchaseOrderLine.setProductName(productName);
}
compute(purchaseOrderLine, purchaseOrder);
return purchaseOrderLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderSupplierService method createPurchaseOrder.
@Transactional(rollbackOn = { Exception.class })
public void createPurchaseOrder(Partner supplierPartner, List<PurchaseOrderLine> purchaseOrderLineList, PurchaseOrder parentPurchaseOrder) throws AxelorException {
LOG.debug("Création d'une commande fournisseur depuis le devis fournisseur : {} et le fournisseur : {}", parentPurchaseOrder.getPurchaseOrderSeq(), supplierPartner.getFullName());
PurchaseOrder purchaseOrder = purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), parentPurchaseOrder.getCompany(), null, supplierPartner.getCurrency(), null, parentPurchaseOrder.getPurchaseOrderSeq(), parentPurchaseOrder.getExternalReference(), Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(parentPurchaseOrder.getCompany()), Beans.get(AppBaseService.class).getTodayDate(parentPurchaseOrder.getCompany()), Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, parentPurchaseOrder.getTradingName());
purchaseOrder.setParentPurchaseOrder(parentPurchaseOrder);
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
purchaseOrder.addPurchaseOrderLineListItem(this.createPurchaseOrderLine(purchaseOrder, purchaseOrderLine));
}
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_REQUESTED);
purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
poRepo.save(purchaseOrder);
}
Aggregations