use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method updateCostPrice.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateCostPrice(PurchaseOrder purchaseOrder) throws AxelorException {
if (purchaseOrder.getPurchaseOrderLineList() != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
Product product = purchaseOrderLine.getProduct();
if (product != null) {
BigDecimal lastPurchasePrice = (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()) ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice();
lastPurchasePrice = currencyService.getAmountCurrencyConvertedAtDate(purchaseOrder.getCurrency(), purchaseOrder.getCompany().getCurrency(), lastPurchasePrice, currencyService.getDateToConvert(null));
productCompanyService.set(product, "lastPurchasePrice", lastPurchasePrice, purchaseOrder.getCompany());
LocalDate lastPurchaseDate = Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
productCompanyService.set(product, "lastPurchaseDate", lastPurchaseDate, purchaseOrder.getCompany());
if ((Boolean) productCompanyService.get(product, "defShipCoefByPartner", purchaseOrder.getCompany())) {
Unit productPurchaseUnit = (Unit) productCompanyService.get(product, "purchasesUnit", purchaseOrder.getCompany());
productPurchaseUnit = productPurchaseUnit != null ? productPurchaseUnit : (Unit) productCompanyService.get(product, "unit", purchaseOrder.getCompany());
BigDecimal convertedQty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), productPurchaseUnit, purchaseOrderLine.getQty(), purchaseOrderLine.getQty().scale(), product);
BigDecimal shippingCoef = Beans.get(ShippingCoefService.class).getShippingCoefDefByPartner(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), convertedQty);
if (shippingCoef.compareTo(BigDecimal.ZERO) != 0) {
productCompanyService.set(product, "shippingCoef", shippingCoef, purchaseOrder.getCompany());
}
}
if ((Integer) productCompanyService.get(product, "costTypeSelect", purchaseOrder.getCompany()) == ProductRepository.COST_TYPE_LAST_PURCHASE_PRICE) {
productCompanyService.set(product, "costPrice", lastPurchasePrice, purchaseOrder.getCompany());
if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", purchaseOrder.getCompany())) {
Beans.get(ProductService.class).updateSalePrice(product, purchaseOrder.getCompany());
}
}
}
}
purchaseOrderRepo.save(purchaseOrder);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method attachToNewPurchaseOrder.
// Attachment of all purchase order lines to new purchase order
public void attachToNewPurchaseOrder(List<PurchaseOrder> purchaseOrderList, PurchaseOrder purchaseOrderMerged) {
for (PurchaseOrder purchaseOrder : purchaseOrderList) {
int countLine = 1;
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
purchaseOrderLine.setSequence(countLine * 10);
purchaseOrderMerged.addPurchaseOrderLineListItem(purchaseOrderLine);
countLine++;
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseProductServiceImpl method getLastShippingCoef.
@Override
public BigDecimal getLastShippingCoef(Product product) throws AxelorException {
PurchaseOrderLine lastPurchaseOrderLine = Beans.get(PurchaseOrderLineRepository.class).all().filter("self.product.id = :productId " + "AND (self.purchaseOrder.statusSelect = :validated " + "OR self.purchaseOrder.statusSelect = :finished)").bind("productId", product.getId()).bind("validated", PurchaseOrderRepository.STATUS_VALIDATED).bind("finished", PurchaseOrderRepository.STATUS_FINISHED).order("-purchaseOrder.validationDate").fetchOne();
if (lastPurchaseOrderLine != null) {
Partner partner = lastPurchaseOrderLine.getPurchaseOrder().getSupplierPartner();
Company company = lastPurchaseOrderLine.getPurchaseOrder().getCompany();
Unit productUnit = Beans.get(PurchaseOrderLineService.class).getPurchaseUnit(lastPurchaseOrderLine);
BigDecimal qty = Beans.get(UnitConversionService.class).convert(lastPurchaseOrderLine.getUnit(), productUnit, lastPurchaseOrderLine.getQty(), lastPurchaseOrderLine.getQty().scale(), product);
return Beans.get(ShippingCoefService.class).getShippingCoef(product, partner, company, qty);
} else {
return BigDecimal.ONE;
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseRequestServiceImpl method generatePo.
@Transactional(rollbackOn = { Exception.class })
@Override
public List<PurchaseOrder> generatePo(List<PurchaseRequest> purchaseRequests, Boolean groupBySupplier, Boolean groupByProduct) throws AxelorException {
List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>();
Map<String, PurchaseOrder> purchaseOrderMap = new HashMap<>();
for (PurchaseRequest purchaseRequest : purchaseRequests) {
PurchaseOrder purchaseOrder;
String key = groupBySupplier ? getPurchaseOrderGroupBySupplierKey(purchaseRequest) : null;
if (key != null && purchaseOrderMap.containsKey(key)) {
purchaseOrder = purchaseOrderMap.get(key);
} else {
purchaseOrder = createPurchaseOrder(purchaseRequest);
key = key == null ? purchaseRequest.getId().toString() : key;
purchaseOrderMap.put(key, purchaseOrder);
}
if (purchaseOrder == null) {
purchaseOrder = createPurchaseOrder(purchaseRequest);
}
for (PurchaseRequestLine purchaseRequestLine : purchaseRequest.getPurchaseRequestLineList()) {
PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
Product product = purchaseRequestLine.getProduct();
purchaseOrderLine = groupByProduct && purchaseOrder != null ? getPoLineByProduct(product, purchaseOrder) : null;
purchaseOrderLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, purchaseRequestLine.getNewProduct() ? purchaseRequestLine.getProductTitle() : null, null, purchaseRequestLine.getQuantity(), purchaseRequestLine.getUnit());
purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
purchaseOrderLineList.add(purchaseOrderLine);
purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrder);
}
purchaseOrder.getPurchaseOrderLineList().addAll(purchaseOrderLineList);
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrderRepo.save(purchaseOrder);
purchaseRequest.setPurchaseOrder(purchaseOrder);
purchaseRequestRepo.save(purchaseRequest);
}
List<PurchaseOrder> purchaseOrders = purchaseOrderMap.values().stream().collect(Collectors.toList());
return purchaseOrders;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class FixedAssetServiceSupplyChainImpl method createFixedAssets.
@Transactional
@Override
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
List<FixedAsset> fixedAssetList = super.createFixedAssets(invoice);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return fixedAssetList;
}
if (fixedAssetList.isEmpty()) {
return new ArrayList<>();
}
StockLocation stockLocation = invoice.getPurchaseOrder() != null ? invoice.getPurchaseOrder().getStockLocation() : null;
for (FixedAsset fixedAsset : fixedAssetList) {
PurchaseOrderLine pol = fixedAsset.getInvoiceLine().getPurchaseOrderLine();
fixedAsset.setStockLocation(stockLocation);
if (fixedAsset.getInvoiceLine().getIncomingStockMove() != null && CollectionUtils.isNotEmpty(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList())) {
fixedAsset.setTrackingNumber(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList().stream().filter(l -> pol.equals(l.getPurchaseOrderLine())).findFirst().map(StockMoveLine::getTrackingNumber).orElse(null));
fixedAsset.setStockLocation(fixedAsset.getInvoiceLine().getIncomingStockMove().getToStockLocation());
}
}
return fixedAssetList;
}
Aggregations