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 @@
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
......@@ -71,7 +68,7 @@
<value> <string>"""\n
Builds the delivery.\n
"""\n
\n
from Products.ERP5Type.Log import log\n
delivery = sci[\'object\']\n
delivery_portal_type = delivery.getPortalType()\n
portal_deliveries = sci.getPortal().portal_deliveries\n
......@@ -84,8 +81,8 @@ builder_by_ptype = {\n
if builder_by_ptype.has_key(delivery_portal_type) :\n
builder = getattr(portal_deliveries, builder_by_ptype[delivery_portal_type], None)\n
if builder is None :\n
context.log(\'accounting_workflow/scripts/Delivery_build\',\n
\'unable to build : no builder in %s\' % builder_by_ptype[delivery_portal_type])\n
log(\'erp5_accounting\',\n
\'unable to build : no builder in %s\' % builder_by_ptype[delivery_portal_type])\n
return\n
\n
### Kev patch: Generate pay sheet accounting lines (inspired by order_workflow)\n
......@@ -174,6 +171,8 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n
<value>
<tuple>
<string>sci</string>
<string>Products.ERP5Type.Log</string>
<string>log</string>
<string>_getitem_</string>
<string>delivery</string>
<string>_getattr_</string>
......@@ -183,7 +182,6 @@ if builder_by_ptype.has_key(delivery_portal_type) :\n
<string>getattr</string>
<string>None</string>
<string>builder</string>
<string>context</string>
<string>PRIORITY</string>
<string>pay_sheet</string>
<string>previous_tag</string>
......
......@@ -3,11 +3,8 @@
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
......@@ -86,10 +83,6 @@ transition = state_change[\'transition\']\n
if transition.id in (\'plan_action\', \'confirm_action\') :\n
skip_period_validation = 1\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
source_section = transaction.getSourceSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\n
......@@ -99,7 +92,8 @@ if source_section is None:\n
destination_section = transaction.getDestinationSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\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
\n
currency = transaction.getResource(portal_type = \'Currency\')\n
......@@ -114,40 +108,42 @@ if not transaction.getStartDate() :\n
raise ValidationFailed(N_(\'Date is not Defined\'))\n
else:\n
if not skip_period_validation :\n
valid_date = False\n
# check the date is in an opened period\n
transaction_date = transaction.getStartDate().earliestTime()\n
\n
openned_accounting_period_list = source_section.searchFolder(\n
portal_type="Accounting Period",\n
# planned is for b/w compatibility\n
simulation_state=("planned", \'started\'))\n
if len(openned_accounting_period_list) == 0 :\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
# we do not account from their side.\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
if source_section is not None:\n
valid_date = False\n
transaction_date = transaction.getStartDate().earliestTime()\n
openned_accounting_period_list = source_section.searchFolder(\n
portal_type="Accounting Period",\n
# planned is for b/w compatibility\n
simulation_state=("planned", \'started\'))\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
# consider that they do not want to use accounting periods or\n
# we do not account from their side.\n
valid_date = True\n
if not valid_date :\n
raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n
"for source section"))\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 not valid_date:\n
raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n
"for source section"))\n
# do the same for destination section \n
if check_destination :\n
if destination_section is not None:\n
valid_date = False\n
transaction_date = transaction.getStopDate().earliestTime()\n
openned_accounting_period_list = destination_section.searchFolder(\n
portal_type = "Accounting Period",\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
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 not valid_date :\n
if not valid_date:\n
raise ValidationFailed(N_("Date is not in an opened Accounting Period "\n
"for destination section"))\n
......@@ -223,7 +219,6 @@ else:\n
<string>_getattr_</string>
<string>skip_period_validation</string>
<string>transition</string>
<string>check_destination</string>
<string>source_section</string>
<string>None</string>
<string>destination_section</string>
......@@ -233,6 +228,7 @@ else:\n
<string>transaction_date</string>
<string>openned_accounting_period_list</string>
<string>len</string>
<string>dict</string>
<string>True</string>
<string>_getiter_</string>
<string>apd</string>
......
465
\ No newline at end of file
468
\ 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