Commit cd8470d6 authored by Jérome Perrin's avatar Jérome Perrin

Generate transaction references using the short title on the corresponding accounting period.

Introduce new scripts to get the accounting period that apply for an accounting transaction

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19693 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b2f2a904
......@@ -83,6 +83,7 @@
<string>my_title</string>
<string>my_start_date</string>
<string>my_stop_date</string>
<string>my_short_title</string>
</list>
</value>
</item>
......
<?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>title</string>
<string>description</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_short_title</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>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string>A short identifier for this accounting period. This will be used to generate references in accounting transactions.</string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Short Title</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</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[
"""Returns the accounting period for the destination section that should be applied for this\n
accounting transaction.\n
"""\n
\n
operation_date = context.getStopDate()\n
if not operation_date:\n
return None\n
\n
section = context.getDestinationSectionValue(portal_type=\'Organisation\')\n
if section is not None:\n
for accounting_period in section.contentValues(\n
portal_type=\'Accounting Period\',\n
checked_permission=\'View\'):\n
if accounting_period.getValidationState() in (\n
\'draft\', \'cancelled\', \'deleted\'):\n
continue\n
if accounting_period.getStartDate().earliestTime()\\\n
<= operation_date <= \\\n
accounting_period.getStopDate().latestTime():\n
return accounting_period\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></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>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_getattr_</string>
<string>context</string>
<string>operation_date</string>
<string>None</string>
<string>section</string>
<string>_getiter_</string>
<string>accounting_period</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_getAccountingPeriodForDestinationSection</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</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[
"""Returns the accounting period for the source section that should be applied for this\n
accounting transaction.\n
"""\n
\n
operation_date = context.getStartDate()\n
if not operation_date:\n
return None\n
\n
section = context.getSourceSectionValue(portal_type=\'Organisation\')\n
if section is not None:\n
for accounting_period in section.contentValues(\n
portal_type=\'Accounting Period\',\n
checked_permission=\'View\'):\n
if accounting_period.getValidationState() in (\n
\'draft\', \'cancelled\', \'deleted\'):\n
continue\n
if accounting_period.getStartDate().earliestTime()\\\n
<= operation_date <= \\\n
accounting_period.getStopDate().latestTime():\n
return accounting_period\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></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>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_getattr_</string>
<string>context</string>
<string>operation_date</string>
<string>None</string>
<string>section</string>
<string>_getiter_</string>
<string>accounting_period</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_getAccountingPeriodForSourceSection</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -82,20 +82,31 @@ if transaction.getPortalType() == \'Sale Invoice Transaction\':\n
default=1)\n
transaction.setReference(invoice_reference)\n
\n
\n
# Generate new values for Source Reference and Destination Reference.\n
if not transaction.getSourceReference():\n
year = transaction.getStartDate().year()\n
source_id_group = (\'accounting\', \'section\', source_section, year)\n
period = transaction.AccountingTransaction_getAccountingPeriodForSourceSection()\n
period_code = \'\'\n
if period is not None:\n
period_code = period.getShortTitle() or period.getTitle() or \'\'\n
if not period_code:\n
period_code = transaction.getStartDate().year()\n
source_id_group = (\'accounting\', \'section\', source_section, period_code)\n
source_reference = transaction.generateNewId(id_group=source_id_group,\n
default=1)\n
transaction.setSourceReference(\'%s-%s\' % (year, source_reference))\n
transaction.setSourceReference(\'%s-%s\' % (period_code, source_reference))\n
\n
if not transaction.getDestinationReference():\n
year = transaction.getStopDate().year()\n
destination_id_group = (\'accounting\', \'section\', destination_section, year)\n
period = transaction.AccountingTransaction_getAccountingPeriodForDestinationSection()\n
period_code = \'\'\n
if period is not None:\n
period_code = period.getShortTitle() or period.getTitle() or \'\'\n
if not period_code:\n
period_code = transaction.getStopDate().year()\n
destination_id_group = (\'accounting\', \'section\', destination_section, period_code)\n
destination_reference = transaction.generateNewId(\n
id_group=destination_id_group, default=1)\n
transaction.setDestinationReference(\'%s-%s\' % (year, destination_reference))\n
transaction.setDestinationReference(\'%s-%s\' % (period_code, destination_reference))\n
</string> </value>
</item>
<item>
......@@ -152,7 +163,9 @@ if not transaction.getDestinationReference():\n
<string>destination_section</string>
<string>invoice_id_group</string>
<string>invoice_reference</string>
<string>year</string>
<string>period</string>
<string>period_code</string>
<string>None</string>
<string>source_id_group</string>
<string>source_reference</string>
<string>destination_id_group</string>
......
630
\ No newline at end of file
631
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment