Search in sources :

Example 36 with PurchaseOrder

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);
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) HashSet(java.util.HashSet)

Example 37 with 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);
    }
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Transactional(com.google.inject.persist.Transactional)

Example 38 with PurchaseOrder

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);
                }
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) StockRules(com.axelor.apps.stock.db.StockRules) Transactional(com.google.inject.persist.Transactional)

Example 39 with PurchaseOrder

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 40 with PurchaseOrder

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;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Aggregations

PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)84 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)26 AxelorException (com.axelor.exception.AxelorException)26 Transactional (com.google.inject.persist.Transactional)16 BigDecimal (java.math.BigDecimal)12 Company (com.axelor.apps.base.db.Company)11 Context (com.axelor.rpc.Context)10 Partner (com.axelor.apps.base.db.Partner)9 Product (com.axelor.apps.base.db.Product)9 ArrayList (java.util.ArrayList)9 Invoice (com.axelor.apps.account.db.Invoice)7 List (java.util.List)7 PurchaseOrderRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)6 SaleOrder (com.axelor.apps.sale.db.SaleOrder)6 PurchaseOrderSupplychainService (com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService)6 LocalDate (java.time.LocalDate)6 PurchaseOrderService (com.axelor.apps.purchase.service.PurchaseOrderService)5 StockMove (com.axelor.apps.stock.db.StockMove)5 Unit (com.axelor.apps.base.db.Unit)4 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)4