svn commit: r812069 - /ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r812069 - /ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy

hansbak-2
Author: hansbak
Date: Mon Sep  7 10:01:35 2009
New Revision: 812069

URL: http://svn.apache.org/viewvc?rev=812069&view=rev
Log:
sometimes timezone changes can cause a duplicate timesheet

Modified:
    ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy

Modified: ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy?rev=812069&r1=812068&r2=812069&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy (original)
+++ ofbiz/trunk/specialpurpose/projectmgr/webapp/projectmgr/WEB-INF/actions/EditWeekTimesheet.groovy Mon Sep  7 10:01:35 2009
@@ -41,11 +41,17 @@
     timesheet = delegator.findByPrimaryKey("Timesheet", ["timesheetId" : timesheetId]);
     partyId = timesheet.partyId; // use the party from this timesheet
 } else {
-    start = UtilDateTime.getWeekStart(UtilDateTime.nowTimestamp());
-    timesheets = delegator.findByAnd("Timesheet", ["partyId" : partyId, "fromDate" : start]);
-    if (timesheets) {
-        timesheet = timesheets[0];
-    } else {
+    // make sure because of timezone changes, not a duplicate timesheet is created
+    midweek = UtilDateTime.addDaysToTimestamp(UtilDateTime.getWeekStart(UtilDateTime.nowTimestamp()),3);
+    entryExprs = EntityCondition.makeCondition([
+        EntityCondition.makeCondition("fromDate", EntityComparisonOperator.LESS_THAN, midweek),
+        EntityCondition.makeCondition("thruDate", EntityComparisonOperator.GREATER_THAN, midweek),
+        EntityCondition.makeCondition("partyId", EntityComparisonOperator.EQUALS, partyId)
+        ], EntityOperator.AND);
+    entryIterator = delegator.find("Timesheet", entryExprs, null, null, null, null);
+    timesheet = entryIterator.next();
+    entryIterator.close();
+    if (timesheet == null) {
         result = dispatcher.runSync("createProjectTimesheet", ["userLogin" : parameters.userLogin, "partyId" : partyId]);
         if (result && result.timesheetId) {
             timesheet = delegator.findByPrimaryKey("Timesheet", ["timesheetId" : result.timesheetId]);