From 2596103d19fa55b162f3f1a473fe931c770e9528 Mon Sep 17 00:00:00 2001 From: Gabriel Monnerat <gabriel@tiolive.com> Date: Mon, 1 Jul 2013 14:37:18 +0000 Subject: [PATCH] Move code to be possible customize reference, source_reference and destination_reference With this, is possible set custom references without overwrite accounting_workflow --- .../AccountingTransaction_setReference.xml | 134 ++++++++++++++++++ .../scripts/setReferences.xml | 70 +-------- bt5/erp5_accounting/bt/revision | 2 +- 3 files changed, 136 insertions(+), 70 deletions(-) create mode 100644 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_setReference.xml diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_setReference.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_setReference.xml new file mode 100644 index 0000000000..35625a3937 --- /dev/null +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_setReference.xml @@ -0,0 +1,134 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + </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># Get sections.\n +source_section = None\n +source_section_value = context.getSourceSectionValue()\n +if source_section_value is not None \\\n + and source_section_value.getPortalType() == \'Organisation\':\n + source_section_value = \\\n + source_section_value.Organisation_getMappingRelatedOrganisation()\n + source_section = source_section_value.getRelativeUrl()\n +\n +destination_section = None\n +destination_section_value = context.getDestinationSectionValue()\n +if destination_section_value is not None \\\n + and destination_section_value.getPortalType() == \'Organisation\':\n + destination_section_value = \\\n + destination_section_value.Organisation_getMappingRelatedOrganisation()\n + destination_section = destination_section_value.getRelativeUrl()\n +\n +portal = context.getPortalObject()\n +id_generator = portal.portal_ids.generateNewId\n +previous_id_getter = portal.portal_ids.getLastGeneratedId\n +\n +# Invoice Reference is automatically filled only for Sale Invoice context.\n +if context.getPortalType() == \'Sale Invoice Transaction\':\n + if not context.getReference():\n + invoice_id_group = (\'accounting\', \'invoice\', source_section)\n + invoice_reference = id_generator(id_generator=\'uid\',\n + id_group=invoice_id_group,\n + default=previous_id_getter(invoice_id_group,\n + default=0) + 1)\n + context.setReference(invoice_reference)\n +\n +\n +# Generate new values for Source Reference and Destination Reference.\n +if not context.getSourceReference():\n + period = context.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 = str(context.getStartDate().year())\n + source_id_group = (\'accounting\', \'section\', source_section, period_code)\n + source_reference = id_generator(id_generator=\'uid\',\n + id_group=source_id_group,\n + default=previous_id_getter(source_id_group,\n + default=0) + 1)\n + context.setSourceReference(\'%s-%s\' % (period_code, source_reference))\n +\n +if not context.getDestinationReference():\n + period = context.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 = str(context.getStopDate().year())\n + destination_id_group = (\'accounting\', \'section\', destination_section, period_code)\n + destination_reference = id_generator(id_generator=\'uid\',\n + id_group=destination_id_group,\n + default=previous_id_getter(destination_id_group,\n + default=0) + 1)\n + context.setDestinationReference(\'%s-%s\' % (period_code, destination_reference))\n +</string> </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>_proxy_roles</string> </key> + <value> + <tuple> + <string>Manager</string> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>AccountingTransaction_setReference</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/setReferences.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/setReferences.xml index 4f88612dee..fa4fb39860 100644 --- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/setReferences.xml +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/setReferences.xml @@ -53,81 +53,13 @@ <value> <string>"""Set automatic references on the document.\n """\n \n -transaction = state_change[\'object\']\n -\n -# Get sections.\n -source_section = None\n -source_section_value = transaction.getSourceSectionValue()\n -if source_section_value is not None \\\n - and source_section_value.getPortalType() == \'Organisation\':\n - source_section_value = \\\n - source_section_value.Organisation_getMappingRelatedOrganisation()\n - source_section = source_section_value.getRelativeUrl()\n -\n -destination_section = None\n -destination_section_value = transaction.getDestinationSectionValue()\n -if destination_section_value is not None \\\n - and destination_section_value.getPortalType() == \'Organisation\':\n - destination_section_value = \\\n - destination_section_value.Organisation_getMappingRelatedOrganisation()\n - destination_section = destination_section_value.getRelativeUrl()\n -\n -id_generator = state_change.getPortal().portal_ids.generateNewId\n -previous_id_getter = state_change.getPortal().portal_ids.getLastGeneratedId\n -\n -# Invoice Reference is automatically filled only for Sale Invoice Transaction.\n -if transaction.getPortalType() == \'Sale Invoice Transaction\':\n - if not transaction.getReference():\n - invoice_id_group = (\'accounting\', \'invoice\', source_section)\n - invoice_reference = id_generator(id_generator=\'uid\',\n - id_group=invoice_id_group,\n - default=previous_id_getter(invoice_id_group,\n - default=0) + 1)\n - transaction.setReference(invoice_reference)\n -\n -\n -# Generate new values for Source Reference and Destination Reference.\n -if not transaction.getSourceReference():\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 = str(transaction.getStartDate().year())\n - source_id_group = (\'accounting\', \'section\', source_section, period_code)\n - source_reference = id_generator(id_generator=\'uid\',\n - id_group=source_id_group,\n - default=previous_id_getter(source_id_group,\n - default=0) + 1)\n - transaction.setSourceReference(\'%s-%s\' % (period_code, source_reference))\n -\n -if not transaction.getDestinationReference():\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 = str(transaction.getStopDate().year())\n - destination_id_group = (\'accounting\', \'section\', destination_section, period_code)\n - destination_reference = id_generator(id_generator=\'uid\',\n - id_group=destination_id_group,\n - default=previous_id_getter(destination_id_group,\n - default=0) + 1)\n - transaction.setDestinationReference(\'%s-%s\' % (period_code, destination_reference))\n +state_change[\'object\'].AccountingTransaction_setReference()\n </string> </value> </item> <item> <key> <string>_params</string> </key> <value> <string>state_change</string> </value> </item> - <item> - <key> <string>_proxy_roles</string> </key> - <value> - <tuple> - <string>Manager</string> - </tuple> - </value> - </item> <item> <key> <string>id</string> </key> <value> <string>setReferences</string> </value> diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision index 8799d84b2b..93682b45ec 100644 --- a/bt5/erp5_accounting/bt/revision +++ b/bt5/erp5_accounting/bt/revision @@ -1 +1 @@ -1537 \ No newline at end of file +1538 \ No newline at end of file -- 2.30.9