use of com.axelor.apps.purchase.db.PurchaseOrder 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.PurchaseOrder in project axelor-open-suite by axelor.
the class MrpServiceImpl method generateProposals.
@Override
@Transactional(rollbackOn = { Exception.class })
public void generateProposals(Mrp mrp, boolean isProposalPerSupplier) throws AxelorException {
Map<Pair<Partner, LocalDate>, PurchaseOrder> purchaseOrders = new HashMap<>();
Map<Partner, PurchaseOrder> purchaseOrdersPerSupplier = new HashMap<>();
List<MrpLine> mrpLineList = mrpLineRepository.all().filter("self.mrp.id = ?1 AND self.proposalToProcess = true", mrp.getId()).order("maturityDate").fetch();
for (MrpLine mrpLine : mrpLineList) {
if (!mrpLine.getProposalGenerated()) {
mrpLineService.generateProposal(mrpLine, purchaseOrders, purchaseOrdersPerSupplier, isProposalPerSupplier);
mrpLine.setProposalToProcess(false);
mrpLineRepository.save(mrpLine);
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class MrpServiceImpl method createPurchaseMrpLines.
@Transactional(rollbackOn = { Exception.class })
protected void createPurchaseMrpLines(Mrp mrp, PurchaseOrderLine purchaseOrderLine, MrpLineType purchaseOrderMrpLineType) throws AxelorException {
PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
LocalDate maturityDate = purchaseOrderLine.getEstimatedDelivDate();
if (maturityDate == null) {
maturityDate = purchaseOrder.getDeliveryDate();
}
if (maturityDate == null) {
maturityDate = purchaseOrderLine.getDesiredDelivDate();
}
maturityDate = this.computeMaturityDate(maturityDate, purchaseOrderMrpLineType);
if (this.isBeforeEndDate(maturityDate) || purchaseOrderMrpLineType.getIgnoreEndDate()) {
Unit unit = purchaseOrderLine.getProduct().getUnit();
BigDecimal qty = purchaseOrderLine.getQty().subtract(purchaseOrderLine.getReceivedQty());
if (!unit.equals(purchaseOrderLine.getUnit())) {
qty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), purchaseOrderLine.getProduct());
}
MrpLine mrpLine = this.createMrpLine(mrp, purchaseOrderLine.getProduct(), purchaseOrderMrpLineType, qty, maturityDate, BigDecimal.ZERO, purchaseOrder.getStockLocation(), purchaseOrderLine);
if (mrpLine != null) {
mrpLine.setSupplierPartner(purchaseOrder.getSupplierPartner());
mrpLineRepository.save(mrpLine);
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method mergePurchaseOrders.
@Transactional(rollbackOn = { Exception.class })
@Override
public PurchaseOrder mergePurchaseOrders(List<PurchaseOrder> purchaseOrderList, Currency currency, Partner supplierPartner, Company company, StockLocation stockLocation, Partner contactPartner, PriceList priceList, TradingName tradingName) throws AxelorException {
String numSeq = "";
String externalRef = "";
for (PurchaseOrder purchaseOrderLocal : purchaseOrderList) {
if (!numSeq.isEmpty()) {
numSeq += "-";
}
numSeq += purchaseOrderLocal.getPurchaseOrderSeq();
if (!externalRef.isEmpty()) {
externalRef += "|";
}
if (purchaseOrderLocal.getExternalReference() != null) {
externalRef += purchaseOrderLocal.getExternalReference();
}
}
PurchaseOrder purchaseOrderMerged = this.createPurchaseOrder(AuthUtils.getUser(), company, contactPartner, currency, null, numSeq, externalRef, stockLocation, appBaseService.getTodayDate(company), priceList, supplierPartner, tradingName);
super.attachToNewPurchaseOrder(purchaseOrderList, purchaseOrderMerged);
this.computePurchaseOrder(purchaseOrderMerged);
purchaseOrderRepo.save(purchaseOrderMerged);
super.removeOldPurchaseOrders(purchaseOrderList);
return purchaseOrderMerged;
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method createPurchaseOrder.
@Override
public PurchaseOrder createPurchaseOrder(User buyerUser, Company company, Partner contactPartner, Currency currency, LocalDate deliveryDate, String internalReference, String externalReference, StockLocation stockLocation, LocalDate orderDate, PriceList priceList, Partner supplierPartner, TradingName tradingName) throws AxelorException {
LOG.debug("Création d'une commande fournisseur : Société = {}, Reference externe = {}, Fournisseur = {}", company.getName(), externalReference, supplierPartner.getFullName());
PurchaseOrder purchaseOrder = super.createPurchaseOrder(buyerUser, company, contactPartner, currency, deliveryDate, internalReference, externalReference, orderDate, priceList, supplierPartner, tradingName);
purchaseOrder.setStockLocation(stockLocation);
purchaseOrder.setPaymentMode(supplierPartner.getOutPaymentMode());
purchaseOrder.setPaymentCondition(supplierPartner.getPaymentCondition());
if (purchaseOrder.getPaymentMode() == null) {
purchaseOrder.setPaymentMode(this.accountConfigService.getAccountConfig(company).getOutPaymentMode());
}
if (purchaseOrder.getPaymentCondition() == null) {
purchaseOrder.setPaymentCondition(this.accountConfigService.getAccountConfig(company).getDefPaymentCondition());
}
purchaseOrder.setTradingName(tradingName);
return purchaseOrder;
}
Aggregations