use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class MrpLineServiceImpl method generatePurchaseProposal.
@Transactional(rollbackOn = { Exception.class })
protected void generatePurchaseProposal(MrpLine mrpLine, Map<Pair<Partner, LocalDate>, PurchaseOrder> purchaseOrders, Map<Partner, PurchaseOrder> purchaseOrdersPerSupplier, boolean isProposalsPerSupplier) throws AxelorException {
Product product = mrpLine.getProduct();
StockLocation stockLocation = mrpLine.getStockLocation();
LocalDate maturityDate = mrpLine.getMaturityDate();
Partner supplierPartner = mrpLine.getSupplierPartner();
if (supplierPartner == null) {
supplierPartner = product.getDefaultSupplierPartner();
if (supplierPartner == null) {
throw new AxelorException(mrpLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MRP_LINE_1), product.getFullName());
}
}
Company company = stockLocation.getCompany();
Pair<Partner, LocalDate> key = null;
PurchaseOrder purchaseOrder = null;
if (isProposalsPerSupplier) {
if (purchaseOrdersPerSupplier != null) {
purchaseOrder = purchaseOrdersPerSupplier.get(supplierPartner);
}
} else {
if (purchaseOrders != null) {
key = Pair.of(supplierPartner, maturityDate);
purchaseOrder = purchaseOrders.get(key);
}
}
if (purchaseOrder == null) {
purchaseOrder = purchaseOrderRepo.save(purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), company, null, supplierPartner.getCurrency(), maturityDate, this.getPurchaseOrderOrigin(mrpLine), null, stockLocation, appBaseService.getTodayDate(company), Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, null));
if (isProposalsPerSupplier) {
if (purchaseOrdersPerSupplier != null) {
purchaseOrdersPerSupplier.put(supplierPartner, purchaseOrder);
}
} else {
if (purchaseOrders != null) {
purchaseOrders.put(key, purchaseOrder);
}
}
if (mrpLine.getMrpLineOriginList().size() == 1) {
if (mrpLine.getMrpLineOriginList().get(0).getRelatedToSelect().equals(MrpLineOriginRepository.RELATED_TO_SALE_ORDER_LINE)) {
purchaseOrder.setGeneratedSaleOrderId(saleOrderLineRepo.find(mrpLine.getMrpLineOriginList().get(0).getRelatedToSelectId()).getSaleOrder().getId());
}
}
}
Unit unit = product.getPurchasesUnit();
BigDecimal qty = mrpLine.getQty();
if (unit == null) {
unit = product.getUnit();
} else {
qty = Beans.get(UnitConversionService.class).convert(product.getUnit(), unit, qty, qty.scale(), product);
}
PurchaseOrderLine poLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, null, null, qty, unit);
poLine.setDesiredDelivDate(maturityDate);
purchaseOrder.addPurchaseOrderLineListItem(poLine);
purchaseOrderService.computePurchaseOrder(purchaseOrder);
linkToOrder(mrpLine, purchaseOrder);
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class MrpServiceImpl method createPurchaseMrpLines.
protected void createPurchaseMrpLines() throws AxelorException {
MrpLineType purchaseOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_PURCHASE_ORDER);
if (purchaseOrderMrpLineType == null) {
return;
}
String statusSelect = purchaseOrderMrpLineType.getStatusSelect();
List<Integer> statusList = StringTool.getIntegerList(statusSelect);
if (statusList.isEmpty()) {
statusList.add(PurchaseOrderRepository.STATUS_VALIDATED);
}
// TODO : Manage the case where order is partially delivered
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLineRepository.all().filter("self.product.id in (?1) AND self.purchaseOrder.stockLocation in (?2) AND self.receiptState != ?3 " + "AND self.purchaseOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, PurchaseOrderRepository.STATE_RECEIVED, statusList).fetch();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
this.createPurchaseMrpLines(mrpRepository.find(mrp.getId()), purchaseOrderLineRepository.find(purchaseOrderLine.getId()), mrpLineTypeRepository.find(purchaseOrderMrpLineType.getId()));
JPA.clear();
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceServiceImpl method generateInvoiceFromLines.
public Invoice generateInvoiceFromLines(PurchaseOrder purchaseOrder, BigDecimal percentSum) throws AxelorException {
if (percentSum.equals(BigDecimal.ZERO)) {
throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_NO_LINES_SELECTED));
}
Map<Long, BigDecimal> qtyToInvoiceMap = new HashMap<>();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
BigDecimal realQty = purchaseOrderLine.getQty().multiply(percentSum).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
qtyToInvoiceMap.put(purchaseOrderLine.getId(), realQty);
if (qtyToInvoiceMap.get(purchaseOrderLine.getId()).compareTo(purchaseOrderLine.getQty()) > 0) {
throw new AxelorException(purchaseOrderLine, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PO_INVOICE_QTY_MAX));
}
}
return this.generateInvoice(purchaseOrder, purchaseOrder.getPurchaseOrderLineList(), qtyToInvoiceMap);
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method computeExTaxTotalWithoutShippingLines.
@Override
public BigDecimal computeExTaxTotalWithoutShippingLines(PurchaseOrder purchaseOrder) {
List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLines == null) {
return BigDecimal.ZERO;
}
BigDecimal exTaxTotal = BigDecimal.ZERO;
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLines) {
if (!purchaseOrderLine.getProduct().getIsShippingCostsProduct()) {
exTaxTotal = exTaxTotal.add(purchaseOrderLine.getExTaxTotal());
}
}
return exTaxTotal;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method generateBudgetDistribution.
@Transactional
@Override
public void generateBudgetDistribution(PurchaseOrder purchaseOrder) {
if (purchaseOrder.getPurchaseOrderLineList() != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
if (purchaseOrderLine.getBudget() != null && (purchaseOrderLine.getBudgetDistributionList() == null || purchaseOrderLine.getBudgetDistributionList().isEmpty())) {
BudgetDistribution budgetDistribution = new BudgetDistribution();
budgetDistribution.setBudget(purchaseOrderLine.getBudget());
budgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal());
purchaseOrderLine.addBudgetDistributionListItem(budgetDistribution);
}
}
// purchaseOrderRepo.save(purchaseOrder);
}
}
Aggregations