Search in sources :

Example 46 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderController method updateEstimatedDelivDate.

public void updateEstimatedDelivDate(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            Integer receiptState = purchaseOrderLine.getReceiptState();
            if (receiptState != null && !receiptState.equals(PurchaseOrderLineRepository.RECEIPT_STATE_RECEIVED) && !receiptState.equals(PurchaseOrderLineRepository.RECEIPT_STATE_PARTIALLY_RECEIVED)) {
                purchaseOrderLine.setEstimatedDelivDate(purchaseOrder.getDeliveryDate());
            }
        }
    }
    response.setValue("purchaseOrderLineList", purchaseOrderLineList);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 47 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method computeAnalyticDistribution.

public void computeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
    if (Beans.get(AppAccountService.class).getAppAccount().getManageAnalyticAccounting()) {
        purchaseOrderLine = Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeAnalyticDistribution(purchaseOrderLine);
        response.setValue("analyticMoveLineList", purchaseOrderLine.getAnalyticMoveLineList());
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine)

Example 48 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method createAnalyticDistributionWithTemplate.

public void createAnalyticDistributionWithTemplate(ActionRequest request, ActionResponse response) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
    purchaseOrderLine = Beans.get(PurchaseOrderLineServiceSupplyChain.class).createAnalyticDistributionWithTemplate(purchaseOrderLine);
    response.setValue("analyticMoveLineList", purchaseOrderLine.getAnalyticMoveLineList());
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine)

Example 49 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class ImportSupplyChain method importPurchaseOrderFromSupplyChain.

@Transactional
public Object importPurchaseOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        PurchaseOrder purchaseOrder = (PurchaseOrder) bean;
        int status = purchaseOrder.getStatusSelect();
        purchaseOrder = (PurchaseOrder) importPurchaseOrder.importPurchaseOrder(bean, values);
        for (PurchaseOrderLine line : purchaseOrder.getPurchaseOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(purchaseOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (status == PurchaseOrderRepository.STATUS_VALIDATED || status == PurchaseOrderRepository.STATUS_FINISHED) {
            purchaseOrderWorkflowService.validatePurchaseOrder(purchaseOrder);
        }
        if (status == PurchaseOrderRepository.STATUS_FINISHED) {
            List<Long> idList = purchaseOrderStockServiceImpl.createStockMoveFromPurchaseOrder(purchaseOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                stockMoveService.copyQtyToRealQty(stockMove);
                stockMoveService.realize(stockMove);
                stockMove.setRealDate(purchaseOrder.getDeliveryDate());
            }
            purchaseOrder.setValidationDate(purchaseOrder.getOrderDate());
            purchaseOrder.setValidatedByUser(AuthUtils.getUser());
            purchaseOrder.setSupplierPartner(purchaseOrderService.validateSupplier(purchaseOrder));
            Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
            String prefixSupplierSeq = "INV000";
            invoice.setSupplierInvoiceNb(prefixSupplierSeq + purchaseOrder.getImportId());
            invoice.setInternalReference(purchaseOrder.getInternalReference());
            LocalDate date;
            if (purchaseOrder.getValidationDate() != null) {
                date = purchaseOrder.getValidationDate();
            } else {
                date = Beans.get(AppBaseService.class).getTodayDate(purchaseOrder.getCompany());
            }
            invoice.setInvoiceDate(date);
            invoice.setOriginDate(date.minusDays(15));
            invoiceService.validateAndVentilate(invoice);
            purchaseOrderWorkflowService.finishPurchaseOrder(purchaseOrder);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ImportPurchaseOrder(com.axelor.apps.purchase.script.ImportPurchaseOrder) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService) Transactional(com.google.inject.persist.Transactional)

Example 50 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method compute.

public void compute(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
        Map<String, BigDecimal> map = Beans.get(PurchaseOrderLineService.class).compute(purchaseOrderLine, purchaseOrder);
        response.setValues(map);
        response.setAttr("priceDiscounted", "hidden", map.getOrDefault("priceDiscounted", BigDecimal.ZERO).compareTo(purchaseOrder.getInAti() ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice()) == 0);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) BigDecimal(java.math.BigDecimal)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5