use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class WorkflowVentilationServiceSupplychainImpl method purchaseOrderProcess.
private void purchaseOrderProcess(Invoice invoice) throws AxelorException {
// Get all different purchaseOrders from invoice
Set<PurchaseOrder> purchaseOrderSet = new HashSet<>();
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
PurchaseOrder purchaseOrder = null;
purchaseOrder = this.purchaseOrderLineProcess(invoice, invoiceLine);
if (purchaseOrder != null) {
purchaseOrderSet.add(purchaseOrder);
}
}
for (PurchaseOrder purchaseOrder : purchaseOrderSet) {
log.debug("Update the invoiced amount of the purchase order : {}", purchaseOrder.getPurchaseOrderSeq());
purchaseOrder.setAmountInvoiced(purchaseOrderInvoiceService.getInvoicedAmount(purchaseOrder, invoice.getId(), false));
purchaseOrderRepository.save(purchaseOrder);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method updatePurchaseOrderOnCancel.
@Transactional(rollbackOn = { Exception.class })
public void updatePurchaseOrderOnCancel(StockMove stockMove) throws AxelorException {
PurchaseOrder po = purchaseOrderRepo.find(stockMove.getOriginId());
updatePurchaseOrderLines(stockMove, stockMove.getIsReversion());
Beans.get(PurchaseOrderStockService.class).updateReceiptState(po);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getTerminatePurchaseOrderOnReceipt()) {
finishOrValidatePurchaseOrderStatus(po);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class StockRulesServiceSupplychainImpl method generatePurchaseOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void generatePurchaseOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
super.generatePurchaseOrder(product, qty, stockLocationLine, type);
return;
}
StockLocation stockLocation = stockLocationLine.getStockLocation();
// TODO à supprimer après suppression des variantes
if (stockLocation == null) {
return;
}
StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
if (stockRules == null) {
return;
}
if (this.useMinStockRules(stockLocationLine, stockRules, qty, type)) {
if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_ALERT)) {
this.generateAndSendMessage(stockRules);
} else if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_PURCHASE_ORDER)) {
BigDecimal minReorderQty = getDefaultSupplierMinQty(product);
BigDecimal qtyToOrder = this.getQtyToOrder(qty, stockLocationLine, type, stockRules, minReorderQty);
Partner supplierPartner = product.getDefaultSupplierPartner();
if (supplierPartner != null) {
Company company = stockLocation.getCompany();
LocalDate today = Beans.get(AppBaseService.class).getTodayDate(company);
PurchaseOrderSupplychainService purchaseOrderSupplychainService = Beans.get(PurchaseOrderSupplychainService.class);
PurchaseOrder purchaseOrder = purchaseOrderRepo.save(purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), company, null, supplierPartner.getCurrency(), today.plusDays(supplierPartner.getDeliveryDelay()), stockRules.getName(), null, stockLocation, today, Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, null));
purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, null, null, qtyToOrder, product.getUnit()));
Beans.get(PurchaseOrderService.class).computePurchaseOrder(purchaseOrder);
purchaseOrderRepo.save(purchaseOrder);
if (stockRules.getAlert()) {
this.generateAndSendMessage(stockRules);
}
}
}
}
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class TimetableServiceImpl method createInvoice.
@Override
public Invoice createInvoice(Timetable timetable) throws AxelorException {
SaleOrder saleOrder = timetable.getSaleOrder();
PurchaseOrder purchaseOrder = timetable.getPurchaseOrder();
if (saleOrder != null) {
if (saleOrder.getCurrency() == null) {
throw new AxelorException(timetable, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), saleOrder.getSaleOrderSeq());
}
List<Long> timetableId = new ArrayList<>();
timetableId.add(timetable.getId());
Invoice invoice = saleOrderInvoiceService.generateInvoice(saleOrder, SaleOrderRepository.INVOICE_TIMETABLES, BigDecimal.ZERO, true, null, timetableId);
return invoice;
}
if (purchaseOrder != null) {
if (purchaseOrder.getCurrency() == null) {
throw new AxelorException(timetable, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), purchaseOrder.getPurchaseOrderSeq());
}
List<Long> timetableId = new ArrayList<>();
timetableId.add(timetable.getId());
return Beans.get(PurchaseOrderInvoiceServiceImpl.class).generateInvoiceFromTimetableForPurchaseOrder(purchaseOrder, timetableId);
}
return null;
}
use of com.axelor.apps.purchase.db.PurchaseOrder in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateCutOffMove.
public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
return null;
}
Company company = stockMove.getCompany();
AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
Partner partner = stockMove.getPartner();
Account partnerAccount = null;
Currency currency = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
currency = saleOrder.getCurrency();
if (partner == null) {
partner = saleOrder.getClientPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
}
if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
currency = purchaseOrder.getCurrency();
if (partner == null) {
partner = purchaseOrder.getSupplierPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
}
String origin = stockMove.getStockMoveSeq();
Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
counter = 0;
this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
move.setStockMove(stockMove);
moveValidateService.validate(move);
} else {
moveRepository.remove(move);
return null;
}
return move;
}
Aggregations