Related to issue 32038: code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Wed, 10 Feb 2016 17:08:23 +0100
changeset 28590 f8d4bab7045b
parent 28589 dbc7082479bb
child 28591 9780a5222687
Related to issue 32038: code review improvements

* startingDate is a mandatory column, so there is no need to validate whether it's null or not
* The promotion is applied for the period of time between the Starting and Ending Dates (both inclusive). For example, for a promotion available only in a concrete date, the starting and ending dates must be equal.
The date received as parameter to this query might have a time (hours/minutes/seconds). To control that situation the comparation is truncating the promotion starting and ending date (that should already be truncated because it's linked to a Date reference), it adds 1 day to the promotion ending date and removes the equal clause. Thus we can properly control the scenario of a one-day promotion with a datetime parameter.
src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java
--- a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java	Mon Feb 01 16:54:12 2016 -0500
+++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java	Wed Feb 10 17:08:23 2016 +0100
@@ -147,8 +147,8 @@
     String hql = "as p ";
     hql += "where active = true ";
     hql += "and client = :client ";
-    hql += "and (endingDate is null or endingDate>=:date) ";
-    hql += "and (startingDate is null or startingDate<=:date) ";
+    hql += "and (endingDate is null or trunc(endingDate) + 1 > :date) ";
+    hql += "and trunc(startingDate)<=:date ";
     hql += "and p.discountType.id = '5D4BAF6BB86D4D2C9ED3D5A6FC051579' ";
     hql += "and (minQuantity is null or minQuantity <= :qty) ";
     hql += "and (maxQuantity is null or maxQuantity >= :qty) ";