use of com.axelor.apps.base.service.ProductCompanyService 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);
}
}
Aggregations