[costadj]Fix issue in HQL query of P&E
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Fri, 05 Sep 2014 11:14:07 +0200
changeset 24865 ae70656351d2
parent 24864 b8d738faf4e2
child 24866 f2260b93dc67
[costadj]Fix issue in HQL query of P&E
src-db/database/sourcedata/AD_TABLE.xml
src/org/openbravo/common/inserters/LCMatchFromInvoiceInserter.java
--- a/src-db/database/sourcedata/AD_TABLE.xml	Fri Sep 05 10:24:15 2014 +0200
+++ b/src-db/database/sourcedata/AD_TABLE.xml	Fri Sep 05 11:14:07 2014 +0200
@@ -11379,7 +11379,7 @@
       where lcra.landedCostCost = lcc)
   ) as products,
   lcm.amount as amttomatch,
-  (select sum(lcm.amount)
+  (select sum(otherlcm.amount)
    from LandedCostMatched as otherlcm
    where otherlcm.landedCostCost = lcc
      and otherlcm.invoiceLine != il 
@@ -11402,8 +11402,8 @@
 from LandedCostCost as lcc
   join lcc.landedCost as lc
   join lcc.landedCostType as lct
-  left join lcc.landedCostMatchedList  as lcm
-  left join lcm.invoiceLine as il
+  left join lcc.landedCostMatchedList as lcm with lcm.invoiceLine.id = :invlineid,
+  InvoiceLine as il
 where (lcc.isMatchingAdjusted = false or lcm is not null)
   and @additional_filters@
   and @insertion_point_0@
--- a/src/org/openbravo/common/inserters/LCMatchFromInvoiceInserter.java	Fri Sep 05 10:24:15 2014 +0200
+++ b/src/org/openbravo/common/inserters/LCMatchFromInvoiceInserter.java	Fri Sep 05 11:14:07 2014 +0200
@@ -33,12 +33,14 @@
   @Override
   public String insertHql(Map<String, String> requestParameters,
       Map<String, Object> queryNamedParameters) {
-    // The query fails with a NPE when using the queryNamedParameters
     final String strInvoiceLineID = requestParameters.get("@InvoiceLine.id@");
     Check.isTrue(IsIDFilter.instance.accept(strInvoiceLineID), "Value " + strInvoiceLineID
         + " is not a valid id.");
-    String strWhereClause = " (il is null or il.id = '" + strInvoiceLineID + "') ";
+    String strWhereClause = " (il is null or il.id = :invlineid2) ";
+    queryNamedParameters.put("invlineid", strInvoiceLineID);
+    queryNamedParameters.put("invlineid2", strInvoiceLineID);
 
+    // The query fails with a NPE when using the queryNamedParameters
     final String strProductId = requestParameters.get("@InvoiceLine.product@");
     if (StringUtils.isNotEmpty(strProductId)) {
       Check.isTrue(IsIDFilter.instance.accept(strProductId), "Value " + strProductId