Search in sources :

Example 1 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method updateProductInformation.

public void updateProductInformation(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
    if (purchaseOrder == null || purchaseOrderLine.getProduct() == null) {
        return;
    }
    try {
        PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
        BigDecimal price = purchaseOrderLine.getProduct().getInAti() ? purchaseOrderLineService.getInTaxUnitPrice(purchaseOrder, purchaseOrderLine, purchaseOrderLine.getTaxLine()) : purchaseOrderLineService.getExTaxUnitPrice(purchaseOrder, purchaseOrderLine, purchaseOrderLine.getTaxLine());
        Map<String, Object> catalogInfo = purchaseOrderLineService.updateInfoFromCatalog(purchaseOrder, purchaseOrderLine);
        Product product = purchaseOrderLine.getProduct();
        String productName = null;
        String productCode = null;
        ProductCompanyService productCompanyService = Beans.get(ProductCompanyService.class);
        if (catalogInfo != null) {
            if (catalogInfo.get("price") != null) {
                price = (BigDecimal) catalogInfo.get("price");
            }
            productName = catalogInfo.get("productName") != null ? (String) catalogInfo.get("productName") : (String) productCompanyService.get(product, "name", purchaseOrder.getCompany());
            productCode = catalogInfo.get("productCode") != null ? (String) catalogInfo.get("productCode") : (String) productCompanyService.get(product, "code", purchaseOrder.getCompany());
        } else {
            productName = (String) productCompanyService.get(product, "name", purchaseOrder.getCompany());
            productCode = (String) productCompanyService.get(product, "code", purchaseOrder.getCompany());
        }
        if (purchaseOrderLine.getProductName() == null) {
            response.setValue("productName", productName);
        }
        if (purchaseOrderLine.getProductCode() == null) {
            response.setValue("productCode", productCode);
        }
        Map<String, Object> discounts = purchaseOrderLineService.getDiscountsFromPriceLists(purchaseOrder, purchaseOrderLine, price);
        if (discounts != null) {
            if (discounts.get("price") != null) {
                price = (BigDecimal) discounts.get("price");
            }
            if (purchaseOrderLine.getProduct().getInAti() != purchaseOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
                response.setValue("discountAmount", purchaseOrderLineService.convertUnitPrice(purchaseOrderLine.getProduct().getInAti(), purchaseOrderLine.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
            } else {
                response.setValue("discountAmount", discounts.get("discountAmount"));
            }
            response.setValue("discountTypeSelect", discounts.get("discountTypeSelect"));
        }
        if (price.compareTo(purchaseOrderLine.getProduct().getInAti() ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice()) != 0) {
            if (purchaseOrderLine.getProduct().getInAti()) {
                response.setValue("inTaxPrice", price);
                response.setValue("price", purchaseOrderLineService.convertUnitPrice(true, purchaseOrderLine.getTaxLine(), price));
            } else {
                response.setValue("price", price);
                response.setValue("inTaxPrice", purchaseOrderLineService.convertUnitPrice(false, purchaseOrderLine.getTaxLine(), price));
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) BigDecimal(java.math.BigDecimal)

Example 2 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrderLineService service = Beans.get(PurchaseOrderLineService.class);
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
        Product product = purchaseOrderLine.getProduct();
        this.resetProductInformation(response);
        response.setValues(service.reset(purchaseOrderLine));
        if (purchaseOrder == null || product == null) {
            return;
        }
        purchaseOrderLine.setPurchaseOrder(purchaseOrder);
        service.fill(purchaseOrderLine, purchaseOrder);
        response.setValues(purchaseOrderLine);
    } 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) Product(com.axelor.apps.base.db.Product) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService)

Example 3 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method checkQty.

public void checkQty(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = getPurchaseOrder(context);
        PurchaseOrderLineService service = Beans.get(PurchaseOrderLineService.class);
        service.checkMinQty(purchaseOrder, purchaseOrderLine, request, response);
        service.checkMultipleQty(purchaseOrderLine, response);
    } 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)

Example 4 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method checkDifferentSupplier.

public void checkDifferentSupplier(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = getPurchaseOrder(context);
        PurchaseOrderLineService service = Beans.get(PurchaseOrderLineService.class);
        service.checkDifferentSupplier(purchaseOrder, purchaseOrderLine, response);
    } 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)

Example 5 with PurchaseOrderLineService

use of com.axelor.apps.purchase.service.PurchaseOrderLineService in project axelor-open-suite by axelor.

the class ImportPurchaseOrderLine method importPurchaseOrderLine.

public Object importPurchaseOrderLine(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof PurchaseOrderLine;
    PurchaseOrderLine purchaseOrderLine = (PurchaseOrderLine) bean;
    PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
    purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrderLine.getPurchaseOrder());
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)6 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)6 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)4 Context (com.axelor.rpc.Context)4 Product (com.axelor.apps.base.db.Product)3 BigDecimal (java.math.BigDecimal)2 Unit (com.axelor.apps.base.db.Unit)1 UnitRepository (com.axelor.apps.base.db.repo.UnitRepository)1 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 ProdHumanResource (com.axelor.apps.production.db.ProdHumanResource)1 ChronoUnit (java.time.temporal.ChronoUnit)1