From eb10ad7fb6a3c9174d7e1db1012dfe96607afe00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 24 Feb 2011 16:02:39 +0000
Subject: [PATCH] when creating secondary periods, create the date in their
 "normal" timezone.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43681 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../AccountingPeriod_createSecondaryPeriod.xml   | 16 ++++++++++++----
 bt5/erp5_accounting/bt/revision                  |  2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml
index c76fe1ecc8..114f615924 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml
@@ -52,6 +52,7 @@
             <key> <string>_body</string> </key>
             <value> <string encoding="cdata"><![CDATA[
 
+from DateTime import DateTime\n
 from Products.ERP5Type.DateUtils import addToDate\n
 from Products.ERP5Type.Message import translateString\n
 \n
@@ -62,12 +63,19 @@ if frequency == \'quarterly\':\n
 date = context.getStartDate()\n
 while date < context.getStopDate():\n
   end_date = addToDate(date, dict(month=month_added))\n
+  # recreate a DateTime to have it in the proper timezone\n
+  start_date = DateTime(date.year(), date.month(), date.day())\n
+  stop_date = DateTime((end_date - 1).year(),\n
+                       (end_date - 1).month(),\n
+                       (end_date - 1).day())\n
+\n
   period = context.newContent(portal_type=\'Accounting Period\',\n
-                     start_date=date,\n
-                     stop_date=end_date - 1,)\n
+                              start_date=start_date,\n
+                              stop_date=stop_date)\n
 \n
   if frequency == \'quarterly\':\n
-    period.setShortTitle(\'%s-%s\' % (date.strftime(\'%Y %m\'), (end_date - 1).strftime(\'%m\')))\n
+    period.setShortTitle(\'%s-%s\' % (\n
+      date.strftime(\'%Y %m\'), (end_date - 1).strftime(\'%m\')))\n
   else:\n
     period.setShortTitle(date.strftime(\'%Y-%m\'))\n
     period.setTitle(str(translateString(date.strftime(\'%B\'))))\n
@@ -77,7 +85,7 @@ while date < context.getStopDate():\n
 \n
   date = end_date\n
   \n
-return context.Base_redirect(form_id, \n
+return context.Base_redirect(form_id,\n
      keep_items=dict(portal_status_message=translateString(\'Accounting periods created.\')))\n
 
 
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index 4541cc8666..a1788aa5b2 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-1453
\ No newline at end of file
+1454
\ No newline at end of file
-- 
2.30.9