Commit 5d143117 authored by Jérome Perrin's avatar Jérome Perrin

validateTransaction: always check date for destination section

Delivery_Build: don't use context.log (this is especially bad in workflow scripts)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17344 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b67a8069
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<string>Products.PythonScripts.PythonScript</string> <tuple/>
<string>PythonScript</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
...@@ -71,7 +68,7 @@ ...@@ -71,7 +68,7 @@
<value> <string>"""\n <value> <string>"""\n
Builds the delivery.\n Builds the delivery.\n
"""\n """\n
\n from Products.ERP5Type.Log import log\n
delivery = sci[\'object\']\n delivery = sci[\'object\']\n
delivery_portal_type = delivery.getPortalType()\n delivery_portal_type = delivery.getPortalType()\n
portal_deliveries = sci.getPortal().portal_deliveries\n portal_deliveries = sci.getPortal().portal_deliveries\n
...@@ -84,7 +81,7 @@ builder_by_ptype = {\n ...@@ -84,7 +81,7 @@ builder_by_ptype = {\n
if builder_by_ptype.has_key(delivery_portal_type) :\n if builder_by_ptype.has_key(delivery_portal_type) :\n
builder = getattr(portal_deliveries, builder_by_ptype[delivery_portal_type], None)\n builder = getattr(portal_deliveries, builder_by_ptype[delivery_portal_type], None)\n
if builder is None :\n if builder is None :\n
context.log(\'accounting_workflow/scripts/Delivery_build\',\n log(\'erp5_accounting\',\n
\'unable to build : no builder in %s\' % builder_by_ptype[delivery_portal_type])\n \'unable to build : no builder in %s\' % builder_by_ptype[delivery_portal_type])\n
return\n return\n
\n \n
...@@ -174,6 +171,8 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n ...@@ -174,6 +171,8 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n
<value> <value>
<tuple> <tuple>
<string>sci</string> <string>sci</string>
<string>Products.ERP5Type.Log</string>
<string>log</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>delivery</string> <string>delivery</string>
<string>_getattr_</string> <string>_getattr_</string>
...@@ -183,7 +182,6 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n ...@@ -183,7 +182,6 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n
<string>getattr</string> <string>getattr</string>
<string>None</string> <string>None</string>
<string>builder</string> <string>builder</string>
<string>context</string>
<string>PRIORITY</string> <string>PRIORITY</string>
<string>pay_sheet</string> <string>pay_sheet</string>
<string>previous_tag</string> <string>previous_tag</string>
......
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<string>Products.PythonScripts.PythonScript</string> <tuple/>
<string>PythonScript</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
...@@ -86,10 +83,6 @@ transition = state_change[\'transition\']\n ...@@ -86,10 +83,6 @@ transition = state_change[\'transition\']\n
if transition.id in (\'plan_action\', \'confirm_action\') :\n if transition.id in (\'plan_action\', \'confirm_action\') :\n
skip_period_validation = 1\n skip_period_validation = 1\n
\n \n
# do we have to care about destination section ?\n
check_destination = (transaction.getPortalType() in\n
transaction.getPortalInvoiceTypeList())\n
\n
# Get sections and a currency.\n # Get sections and a currency.\n
source_section = transaction.getSourceSectionValue(\n source_section = transaction.getSourceSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\n portal_type=[\'Organisation\', \'Person\'])\n
...@@ -99,7 +92,8 @@ if source_section is None:\n ...@@ -99,7 +92,8 @@ if source_section is None:\n
destination_section = transaction.getDestinationSectionValue(\n destination_section = transaction.getDestinationSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\n portal_type=[\'Organisation\', \'Person\'])\n
# if it\'s not an invoice, then we can validate without destination\n # if it\'s not an invoice, then we can validate without destination\n
if destination_section is None and check_destination :\n if destination_section is None and \\\n
transaction.getPortalType() in transaction.getPortalInvoiceTypeList():\n
raise ValidationFailed(N_(\'Destination Section is not Defined.\'))\n raise ValidationFailed(N_(\'Destination Section is not Defined.\'))\n
\n \n
currency = transaction.getResource(portal_type = \'Currency\')\n currency = transaction.getResource(portal_type = \'Currency\')\n
...@@ -114,15 +108,16 @@ if not transaction.getStartDate() :\n ...@@ -114,15 +108,16 @@ if not transaction.getStartDate() :\n
raise ValidationFailed(N_(\'Date is not Defined\'))\n raise ValidationFailed(N_(\'Date is not Defined\'))\n
else:\n else:\n
if not skip_period_validation :\n if not skip_period_validation :\n
valid_date = False\n
# check the date is in an opened period\n # check the date is in an opened period\n
if source_section is not None:\n
valid_date = False\n
transaction_date = transaction.getStartDate().earliestTime()\n transaction_date = transaction.getStartDate().earliestTime()\n
\n
openned_accounting_period_list = source_section.searchFolder(\n openned_accounting_period_list = source_section.searchFolder(\n
portal_type="Accounting Period",\n portal_type="Accounting Period",\n
# planned is for b/w compatibility\n # planned is for b/w compatibility\n
simulation_state=("planned", \'started\'))\n simulation_state=("planned", \'started\'))\n
if len(openned_accounting_period_list) == 0 :\n if not len(source_section.contentValues(\n
filter=dict(portal_type="Accounting Period"))):\n
# if the entity doesn\'t have any accounting period, we can\n # if the entity doesn\'t have any accounting period, we can\n
# consider that they do not want to use accounting periods or\n # consider that they do not want to use accounting periods or\n
# we do not account from their side.\n # we do not account from their side.\n
...@@ -131,23 +126,24 @@ else:\n ...@@ -131,23 +126,24 @@ else:\n
apd = apd.getObject()\n apd = apd.getObject()\n
if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
valid_date = True\n valid_date = True\n
if not valid_date :\n if not valid_date:\n
raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n
"for source section"))\n "for source section"))\n
# do the same for destination section \n # do the same for destination section \n
if check_destination :\n if destination_section is not None:\n
valid_date = False\n valid_date = False\n
transaction_date = transaction.getStopDate().earliestTime()\n transaction_date = transaction.getStopDate().earliestTime()\n
openned_accounting_period_list = destination_section.searchFolder(\n openned_accounting_period_list = destination_section.searchFolder(\n
portal_type = "Accounting Period",\n portal_type = "Accounting Period",\n
simulation_state = (\'planned\', \'started\'))\n simulation_state = (\'planned\', \'started\'))\n
if len(openned_accounting_period_list) == 0:\n if not len(destination_section.contentValues(\n
filter=dict(portal_type="Accounting Period"))):\n
valid_date = True\n valid_date = True\n
for apd in openned_accounting_period_list:\n for apd in openned_accounting_period_list:\n
apd = apd.getObject()\n apd = apd.getObject()\n
if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
valid_date = True\n valid_date = True\n
if not valid_date :\n if not valid_date:\n
raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n
"for destination section"))\n "for destination section"))\n
...@@ -223,7 +219,6 @@ else:\n ...@@ -223,7 +219,6 @@ else:\n
<string>_getattr_</string> <string>_getattr_</string>
<string>skip_period_validation</string> <string>skip_period_validation</string>
<string>transition</string> <string>transition</string>
<string>check_destination</string>
<string>source_section</string> <string>source_section</string>
<string>None</string> <string>None</string>
<string>destination_section</string> <string>destination_section</string>
...@@ -233,6 +228,7 @@ else:\n ...@@ -233,6 +228,7 @@ else:\n
<string>transaction_date</string> <string>transaction_date</string>
<string>openned_accounting_period_list</string> <string>openned_accounting_period_list</string>
<string>len</string> <string>len</string>
<string>dict</string>
<string>True</string> <string>True</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>apd</string> <string>apd</string>
......
465 468
\ No newline at end of file \ 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