From 74602539b700cc52bf45de34b642d851b6922610 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 6 May 2009 15:34:40 +0000
Subject: [PATCH] 2009-05-06 Jerome * Introduce recursive accounting periods,
 used for example for monthly intermediate periods. They do not create balance
 transaction, but prevent adding more transaction for this period.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26852 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../create_secondary_periods.xml              |  95 ++++++
 .../allowed_content_types.xml                 |   5 +-
 ...AccountingPeriod_createSecondaryPeriod.xml | 164 ++++++++++
 .../erp5_accounting/AccountingPeriod_view.xml |   9 +
 .../listbox_period_list.xml                   | 109 +++++++
 ...Period_viewCreateSecondaryPeriodDialog.xml | 152 +++++++++
 .../your_frequency.xml                        | 292 ++++++++++++++++++
 .../your_open_periods.xml                     | 171 ++++++++++
 .../your_profit_and_loss_account.xml          |  29 +-
 .../my_source_section.xml                     |  17 +-
 .../scripts/checkTransactionsState.xml        |   7 +-
 .../scripts/createBalanceTransaction.xml      |   5 +
 .../scripts/validateTransaction.xml           |  32 +-
 bt5/erp5_accounting/bt/change_log             |   3 +
 bt5/erp5_accounting/bt/revision               |   2 +-
 .../bt/template_action_path_list              |   1 +
 ...late_portal_type_allowed_content_type_list |   1 +
 17 files changed, 1068 insertions(+), 26 deletions(-)
 create mode 100644 bt5/erp5_accounting/ActionTemplateItem/portal_types/Accounting%20Period/create_secondary_periods.xml
 create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml
 create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view/listbox_period_list.xml
 create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog.xml
 create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_frequency.xml
 create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_open_periods.xml

diff --git a/bt5/erp5_accounting/ActionTemplateItem/portal_types/Accounting%20Period/create_secondary_periods.xml b/bt5/erp5_accounting/ActionTemplateItem/portal_types/Accounting%20Period/create_secondary_periods.xml
new file mode 100644
index 0000000000..c80ec98d1f
--- /dev/null
+++ b/bt5/erp5_accounting/ActionTemplateItem/portal_types/Accounting%20Period/create_secondary_periods.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>action</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>category</string> </key>
+            <value> <string>object_action</string> </value>
+        </item>
+        <item>
+            <key> <string>condition</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>icon</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>create_secondary_periods</string> </value>
+        </item>
+        <item>
+            <key> <string>permissions</string> </key>
+            <value>
+              <tuple>
+                <string>Add portal content</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>priority</string> </key>
+            <value> <float>2.0</float> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Create Secondary Periods</string> </value>
+        </item>
+        <item>
+            <key> <string>visible</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <tuple>
+        <global name="Expression" module="Products.CMFCore.Expression"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string>string:${object_url}/AccountingPeriod_viewCreateSecondaryPeriodDialog</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <tuple>
+        <global name="Expression" module="Products.CMFCore.Expression"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string>python: object.getParentValue().getPortalType() == \'Organisation\' and not len(object.contentValues(checked_permission=\'View\'))</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/PortalTypeAllowedContentTypeTemplateItem/allowed_content_types.xml b/bt5/erp5_accounting/PortalTypeAllowedContentTypeTemplateItem/allowed_content_types.xml
index 5ccb492412..c2aa282ec0 100644
--- a/bt5/erp5_accounting/PortalTypeAllowedContentTypeTemplateItem/allowed_content_types.xml
+++ b/bt5/erp5_accounting/PortalTypeAllowedContentTypeTemplateItem/allowed_content_types.xml
@@ -2,6 +2,9 @@
  <portal_type id="Account Module">
   <item>Account</item>
  </portal_type>
+ <portal_type id="Accounting Period">
+  <item>Accounting Period</item>
+ </portal_type>
  <portal_type id="Accounting Rule Cell">
   <item>Accounting Rule Cell Line</item>
   <item>Accounting Transaction Line</item>
@@ -56,8 +59,8 @@
   <item>Payment Rule</item>
  </portal_type>
  <portal_type id="Sale Invoice Transaction">
-  <item>File</item>
   <item>Sale Invoice Transaction Line</item>
+  <item>File</item>
   <item>Image</item>
  </portal_type>
 </allowed_content_type_list>
\ No newline at end of file
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
new file mode 100644
index 0000000000..6f2751ab7c
--- /dev/null
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createSecondaryPeriod.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+from Products.ERP5Type.DateUtils import addToDate\n
+\n
+month_added = 1\n
+if frequency == \'quarterly\':\n
+  month_added = 3\n
+\n
+date = context.getStartDate()\n
+while date < context.getStopDate():\n
+  end_date = addToDate(date, dict(month=month_added))\n
+  period = context.newContent(portal_type=\'Accounting Period\',\n
+                     start_date=date,\n
+                     stop_date=end_date - 1,)\n
+\n
+  if frequency == \'quarterly\':\n
+    period.setShortTitle(\'%s-%s\' % (date.strftime(\'%Y %m\'), (end_date - 1).strftime(\'%m\')))\n
+  else:\n
+    period.setShortTitle(date.strftime(\'%Y-%m\'))\n
+    period.setTitle(date.strftime(\'%B\'))\n
+\n
+  if open_periods:\n
+    period.start()\n
+\n
+  date = end_date\n
+  \n
+return context.Base_redirect(form_id, \n
+     keep_items=dict(portal_status_message=\'Accounting periods created.\'))\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>frequency, open_periods=0, form_id=\'view\'</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>3</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>frequency</string>
+                            <string>open_periods</string>
+                            <string>form_id</string>
+                            <string>Products.ERP5Type.DateUtils</string>
+                            <string>addToDate</string>
+                            <string>month_added</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>date</string>
+                            <string>dict</string>
+                            <string>end_date</string>
+                            <string>period</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <tuple>
+                <int>0</int>
+                <string>view</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>AccountingPeriod_createSecondaryPeriod</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view.xml
index 8ea0345b3f..135b8f24a3 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view.xml
@@ -55,6 +55,7 @@
                 <string>left</string>
                 <string>right</string>
                 <string>center</string>
+                <string>bottom</string>
               </list>
             </value>
         </item>
@@ -62,6 +63,14 @@
             <key> <string>groups</string> </key>
             <value>
               <dictionary>
+                <item>
+                    <key> <string>bottom</string> </key>
+                    <value>
+                      <list>
+                        <string>listbox_period_list</string>
+                      </list>
+                    </value>
+                </item>
                 <item>
                     <key> <string>center</string> </key>
                     <value>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view/listbox_period_list.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view/listbox_period_list.xml
new file mode 100644
index 0000000000..64a9a28174
--- /dev/null
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_view/listbox_period_list.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>delegated_list</string> </key>
+            <value>
+              <list>
+                <string>selection_name</string>
+              </list>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>listbox_period_list</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>selection_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>all_editable_columns</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string>listbox_period_list</string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string>Organisation_viewFinancialInformationList</string> </value>
+                </item>
+                <item>
+                    <key> <string>selection_name</string> </key>
+                    <value> <string>accounting_period_accounting_period_selection</string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string>Click to edit the target</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog.xml
new file mode 100644
index 0000000000..bc25b16405
--- /dev/null
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ERP5Form" module="Products.ERP5Form.Form"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_objects</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>action</string> </key>
+            <value> <string>AccountingPeriod_createSecondaryPeriod</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>edit_order</string> </key>
+            <value>
+              <list/>
+            </value>
+        </item>
+        <item>
+            <key> <string>encoding</string> </key>
+            <value> <string>UTF-8</string> </value>
+        </item>
+        <item>
+            <key> <string>enctype</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>group_list</string> </key>
+            <value>
+              <list>
+                <string>left</string>
+                <string>right</string>
+                <string>center</string>
+                <string>bottom</string>
+                <string>hidden</string>
+              </list>
+            </value>
+        </item>
+        <item>
+            <key> <string>groups</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>bottom</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>center</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>left</string> </key>
+                    <value>
+                      <list>
+                        <string>your_frequency</string>
+                        <string>your_open_periods</string>
+                      </list>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>right</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>AccountingPeriod_viewCreateSecondaryPeriodDialog</string> </value>
+        </item>
+        <item>
+            <key> <string>method</string> </key>
+            <value> <string>POST</string> </value>
+        </item>
+        <item>
+            <key> <string>name</string> </key>
+            <value> <string>AccountingPeriod_viewCreateSecondaryPeriodDialog</string> </value>
+        </item>
+        <item>
+            <key> <string>pt</string> </key>
+            <value> <string>form_dialog</string> </value>
+        </item>
+        <item>
+            <key> <string>row_length</string> </key>
+            <value> <int>4</int> </value>
+        </item>
+        <item>
+            <key> <string>stored_encoding</string> </key>
+            <value> <string>UTF-8</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Create Secondary Periods</string> </value>
+        </item>
+        <item>
+            <key> <string>unicode_mode</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>update_action</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_frequency.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_frequency.xml
new file mode 100644
index 0000000000..e9a42e7412
--- /dev/null
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_frequency.xml
@@ -0,0 +1,292 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ListField" module="Products.Formulator.StandardFields"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>your_frequency</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+                <item>
+                    <key> <string>required_not_found</string> </key>
+                    <value> <string>Input is required but no input given.</string> </value>
+                </item>
+                <item>
+                    <key> <string>unknown_selection</string> </key>
+                    <value> <string>You selected an item that was not in the list.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra_item</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>first_item</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>items</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>size</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra_item</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>first_item</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>items</string> </key>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>size</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string>Frequency of the created periods</string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra_item</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>first_item</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>items</string> </key>
+                    <value>
+                      <list>
+                        <tuple>
+                          <string>Monthly</string>
+                          <string>monthly</string>
+                        </tuple>
+                        <tuple>
+                          <string>Quarterly</string>
+                          <string>quarterly</string>
+                        </tuple>
+                      </list>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>size</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>Frequency</string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <tuple>
+        <global name="TALESMethod" module="Products.Formulator.TALESField"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_text</string> </key>
+            <value> <string>python: [(context.Base_translateString(x[0]), x[1]) for x in field.get_orig_value(\'items\')]</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_open_periods.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_open_periods.xml
new file mode 100644
index 0000000000..3e71bca7b9
--- /dev/null
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewCreateSecondaryPeriodDialog/your_open_periods.xml
@@ -0,0 +1,171 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="CheckBoxField" module="Products.Formulator.StandardFields"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>your_open_periods</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string>Open the created periods</string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>Open Periods ?</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewDeliverWorkflowActionDialog/your_profit_and_loss_account.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewDeliverWorkflowActionDialog/your_profit_and_loss_account.xml
index 3a488f2847..24100b49a8 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewDeliverWorkflowActionDialog/your_profit_and_loss_account.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_viewDeliverWorkflowActionDialog/your_profit_and_loss_account.xml
@@ -133,7 +133,9 @@
                 </item>
                 <item>
                     <key> <string>enabled</string> </key>
-                    <value> <string></string> </value>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                    </value>
                 </item>
                 <item>
                     <key> <string>external_validator</string> </key>
@@ -158,7 +160,7 @@
                 <item>
                     <key> <string>items</string> </key>
                     <value>
-                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                      <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
                     </value>
                 </item>
                 <item>
@@ -267,11 +269,24 @@
   <record id="2" aka="AAAAAAAAAAI=">
     <pickle>
       <tuple>
-        <tuple>
-          <string>Products.Formulator.TALESField</string>
-          <string>TALESMethod</string>
-        </tuple>
-        <none/>
+        <global name="TALESMethod" module="Products.Formulator.TALESField"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_text</string> </key>
+            <value> <string>python: context.getParentValue().getPortalType() != context.getPortalType()</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <tuple>
+        <global name="TALESMethod" module="Products.Formulator.TALESField"/>
+        <tuple/>
       </tuple>
     </pickle>
     <pickle>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_viewSourceAccounting/my_source_section.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_viewSourceAccounting/my_source_section.xml
index 8cc59feaba..179e13be05 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_viewSourceAccounting/my_source_section.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/PurchaseInvoiceTransaction_viewSourceAccounting/my_source_section.xml
@@ -13,14 +13,7 @@
             <key> <string>delegated_list</string> </key>
             <value>
               <list>
-                <string>read_only</string>
-                <string>editable_permission</string>
                 <string>title</string>
-                <string>not_viewable</string>
-                <string>required</string>
-                <string>viewable_permission</string>
-                <string>viewable_role</string>
-                <string>editable_role</string>
                 <string>items</string>
               </list>
             </value>
@@ -108,6 +101,12 @@
                     <key> <string>form_id</string> </key>
                     <value> <string>AccountingTransaction_viewFieldLibrary</string> </value>
                 </item>
+                <item>
+                    <key> <string>items</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
                 <item>
                     <key> <string>not_viewable</string> </key>
                     <value> <int>0</int> </value>
@@ -116,10 +115,6 @@
                     <key> <string>read_only</string> </key>
                     <value> <int>0</int> </value>
                 </item>
-                <item>
-                    <key> <string>required</string> </key>
-                    <value> <int>1</int> </value>
-                </item>
                 <item>
                     <key> <string>target</string> </key>
                     <value> <string>Click to edit the target</string> </value>
diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/checkTransactionsState.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/checkTransactionsState.xml
index 868d089b61..b06d49e3cf 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/checkTransactionsState.xml
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/checkTransactionsState.xml
@@ -65,8 +65,12 @@ all_state_list = [x[1] for x in\n
 invalid_simulation_state_list = [state for state in all_state_list\n
                                  if state not in valid_simulation_state_list]\n
 \n
+section = period.getParentValue()\n
+while section.getPortalType() == period.getPortalType():\n
+  section = section.getParentValue()\n
+\n
 movement_list = portal.portal_simulation.getMovementHistoryList(\n
-      section_uid=period.getParentUid(),\n
+      section_uid=section.getUid(),\n
       from_date=period.getStartDate().earliestTime(),\n
       at_date=period.getStopDate().latestTime(),\n
       simulation_state=invalid_simulation_state_list,\n
@@ -128,6 +132,7 @@ if movement_list:\n
                             <string>all_state_list</string>
                             <string>state</string>
                             <string>invalid_simulation_state_list</string>
+                            <string>section</string>
                             <string>movement_list</string>
                           </tuple>
                         </value>
diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/createBalanceTransaction.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/createBalanceTransaction.xml
index 2350f56001..0803b82820 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/createBalanceTransaction.xml
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/createBalanceTransaction.xml
@@ -56,6 +56,11 @@
             <value> <string>"""Create a balance transaction\n
 """\n
 accounting_period = sci[\'object\']\n
+\n
+# we only create a balance transaction for top level accounting periods\n
+if accounting_period.getParentValue().getPortalType() == accounting_period.getPortalType():\n
+  return\n
+\n
 portal = accounting_period.getPortalObject()\n
 profit_and_loss_account = portal.portal_workflow.getInfoFor(\n
                             accounting_period, \'profit_and_loss_account\')\n
diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.xml
index c98d16a3fc..3096dc9377 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.xml
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.xml
@@ -96,6 +96,23 @@ if transaction.getSourceSectionValue(portal_type=\'Category\') is not None or\\\
 transaction_line_list = transaction.getMovementList(\n
         portal_type=transaction.getPortalAccountingMovementTypeList())\n
 \n
+\n
+def checkAccountingPeriodRecusivly(accounting_period, transaction_date):\n
+  valid = accounting_period.getSimulationState() in (\'planned\', \'started\')\n
+  if not valid:\n
+    return False\n
+  for sub_accounting_period in accounting_period.contentValues():\n
+    if sub_accounting_period.getSimulationState() in (\n
+                                        \'deleted\', \'cancelled\'):\n
+      continue\n
+    if sub_accounting_period.getStartDate().earliestTime() <= \\\n
+            transaction_date <= \\\n
+            sub_accounting_period.getStopDate().latestTime():\n
+      if not checkAccountingPeriodRecusivly(sub_accounting_period,\n
+                                            transaction_date):\n
+        return False\n
+  return True\n
+\n
 if not skip_period_validation :\n
   # check the date is in an opened period\n
   if source_section is not None:\n
@@ -120,8 +137,10 @@ if not skip_period_validation :\n
       valid_date = True\n
     for apd in openned_accounting_period_list:\n
       apd = apd.getObject()\n
-      if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
-        valid_date = True\n
+      if apd.getStartDate().earliestTime() <= transaction_date <= \\\n
+                apd.getStopDate().latestTime():\n
+        valid_date = checkAccountingPeriodRecusivly(apd, transaction_date)\n
+\n
     if not valid_date:\n
       raise ValidationFailed(translateString("Date is not in a started Accounting Period "\n
                                              "for source section."))\n
@@ -144,10 +163,12 @@ if not skip_period_validation :\n
       valid_date = True\n
     for apd in openned_accounting_period_list:\n
       apd = apd.getObject()\n
-      if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
-        valid_date = True\n
+      if apd.getStartDate().earliestTime() <= transaction_date <= \\\n
+                  apd.getStopDate().latestTime():\n
+        valid_date = checkAccountingPeriodRecusivly(apd, transaction_date)\n
+\n
     if not valid_date:\n
-      raise ValidationFailed(translateString("Date is not in an started Accounting Period "\n
+      raise ValidationFailed(translateString("Date is not in a started Accounting Period "\n
                                              "for destination section."))\n
 
 
@@ -219,6 +240,7 @@ if not skip_period_validation :\n
                             <string>destination_section</string>
                             <string>None</string>
                             <string>transaction_line_list</string>
+                            <string>checkAccountingPeriodRecusivly</string>
                             <string>False</string>
                             <string>valid_date</string>
                             <string>True</string>
diff --git a/bt5/erp5_accounting/bt/change_log b/bt5/erp5_accounting/bt/change_log
index 4126c0b6cf..d577796fd0 100644
--- a/bt5/erp5_accounting/bt/change_log
+++ b/bt5/erp5_accounting/bt/change_log
@@ -1,3 +1,6 @@
+2009-05-06 Jerome
+* Introduce recursive accounting periods, used for example for monthly intermediate periods. They do not create balance transaction, but prevent adding more transaction for this period.
+
 2009-04-18 Kazuhiko
 * Version 5.4.1
 
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index 11758cc314..03204565ba 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-909
\ No newline at end of file
+911
\ No newline at end of file
diff --git a/bt5/erp5_accounting/bt/template_action_path_list b/bt5/erp5_accounting/bt/template_action_path_list
index ae27c67d90..ffedd21971 100644
--- a/bt5/erp5_accounting/bt/template_action_path_list
+++ b/bt5/erp5_accounting/bt/template_action_path_list
@@ -5,6 +5,7 @@ Account | jump_active_accounting_pref
 Account | jump_to_accounting
 Account | transaction_list
 Account | view
+Accounting Period | create_secondary_periods
 Accounting Period | jump_related_balance_transaction
 Accounting Period | view
 Accounting Rule Cell Line | view
diff --git a/bt5/erp5_accounting/bt/template_portal_type_allowed_content_type_list b/bt5/erp5_accounting/bt/template_portal_type_allowed_content_type_list
index f95fc28c51..aef52c1afe 100644
--- a/bt5/erp5_accounting/bt/template_portal_type_allowed_content_type_list
+++ b/bt5/erp5_accounting/bt/template_portal_type_allowed_content_type_list
@@ -1,4 +1,5 @@
 Account Module | Account
+Accounting Period | Accounting Period
 Accounting Rule Cell | Accounting Rule Cell Line
 Accounting Rule Cell | Accounting Transaction Line
 Accounting Transaction Module | Accounting Transaction
-- 
2.30.9