[hqlpickandexecute] Use placeholder to calculate the unit price in the transformer
authorAugusto Mauch <augusto.mauch@openbravo.com>
Wed, 18 Jun 2014 19:39:30 +0200
changeset 25422 34f132a26f80
parent 25421 eec2bf3f7c72
child 25423 7c059d3c524c
[hqlpickandexecute] Use placeholder to calculate the unit price in the transformer
src-db/database/sourcedata/AD_TABLE.xml
src/org/openbravo/common/datasource/ReturnToFromCustomerVendorHQLTransformer.java
--- a/src-db/database/sourcedata/AD_TABLE.xml	Mon Jun 16 18:24:08 2014 +0200
+++ b/src-db/database/sourcedata/AD_TABLE.xml	Wed Jun 18 19:39:30 2014 +0200
@@ -11485,10 +11485,10 @@
 coalesce((select ol.tax from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol) ,
 (select e.salesOrderLine.tax from ProcurementPOInvoiceMatch as e where e.goodsShipmentLine = iol)) as tax,
 (case when (select e.salesOrderLine.salesOrder.priceList.priceIncludesTax from ProcurementPOInvoiceMatch as e where e.goodsShipmentLine = iol) = true then
- coalesce((select ol.unitPrice from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol), 
+ coalesce((select ol.@unitPriceProperty@ from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol), 
           (select e.salesOrderLine.grossUnitPrice from ProcurementPOInvoiceMatch as e where e.goodsShipmentLine = iol))
 else 
- coalesce((select ol.unitPrice from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol), 
+ coalesce((select ol.@unitPriceProperty@ from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol), 
           (select e.salesOrderLine.unitPrice from ProcurementPOInvoiceMatch as e where e.goodsShipmentLine = iol))
 end) as unitPrice,
 (select e.salesOrderLine.salesOrder.documentNo from ProcurementPOInvoiceMatch as e where e.goodsShipmentLine = iol) as orderNo
--- a/src/org/openbravo/common/datasource/ReturnToFromCustomerVendorHQLTransformer.java	Mon Jun 16 18:24:08 2014 +0200
+++ b/src/org/openbravo/common/datasource/ReturnToFromCustomerVendorHQLTransformer.java	Wed Jun 18 19:39:30 2014 +0200
@@ -22,6 +22,8 @@
 import java.util.Map;
 
 import org.openbravo.client.kernel.ComponentProvider;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.order.Order;
 import org.openbravo.service.datasource.hql.HqlQueryTransformer;
 
 @ComponentProvider.Qualifier("CDB9DC9655F24DF8AB41AA0ADBD04390")
@@ -34,6 +36,8 @@
   private static final String returnReasonLeftClause = " coalesce((select ol.returnReason from OrderLine as ol where ol.salesOrder.id = :salesOrderId and ol.goodsShipmentLine = iol), '')";
   private static final String returnReasonCountQuery = " select count(distinct e.name) from ReturnReason as e where exists (select distinct ol.returnReason from OrderLine as ol where ol.returnReason = e and ol.salesOrder.id = :salesOrderId) ";
   private static final String returnReasonDataQuery = " select distinct e.name from ReturnReason as e where exists (select distinct ol.returnReason from OrderLine as ol where ol.returnReason = e and ol.salesOrder.id = :salesOrderId) ";
+  private static final String unitPriceProperty = "unitPrice";
+  private static final String grossUnitPriceProperty = "grossUnitPrice";
 
   @Override
   public String transformHqlQuery(String hqlQuery, Map<String, String> requestParameters,
@@ -51,6 +55,15 @@
     transformedHqlQuery = transformedHqlQuery.replace("@returnedOthersLeftClause@",
         returnedOthersLeftClause);
 
+    Order order = OBDal.getInstance().get(Order.class, salesOrderId);
+    if (order.getPriceList().isPriceIncludesTax()) {
+      transformedHqlQuery = transformedHqlQuery.replaceAll("@unitPriceProperty@",
+          grossUnitPriceProperty);
+    } else {
+      transformedHqlQuery = transformedHqlQuery
+          .replaceAll("@unitPriceProperty@", unitPriceProperty);
+    }
+
     String distinctProperty = requestParameters.get("_distinct");
     if ("returnReason".equals(distinctProperty)) {
       // Uses custom queries for the return reason column