From afbd18a00018a128753caa52b99569c53fb35b16 Mon Sep 17 00:00:00 2001 From: Mame Coumba Sall <mame@nexedi.com> Date: Thu, 11 Jun 2009 10:44:15 +0000 Subject: [PATCH] 2009-06-11 mame *add condition on script to avoid creating items with the same reference *checkConsistency before validation of item git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27519 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../erp5_item/DeliveryLine_createItemList.xml | 31 +++-- .../portal_workflow/item_workflow/scripts.xml | 6 + .../scripts/checkConsistency.xml | 125 ++++++++++++++++++ .../transitions/validate_action.xml | 2 +- bt5/erp5_item/bt/revision | 2 +- 5 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts/checkConsistency.xml diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/DeliveryLine_createItemList.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/DeliveryLine_createItemList.xml index ba61a55ea1..1211590efb 100644 --- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/DeliveryLine_createItemList.xml +++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/DeliveryLine_createItemList.xml @@ -90,15 +90,23 @@ base_id = \'movement\'\n for line in kw.get(\'listbox\'):\n \n if line.has_key(\'listbox_key\') and (line[\'title\'] or line[\'reference\'] not in (\'\', None)):\n -\n - module = context.getDefaultModule(item_portal_type)\n - item = module.newContent(portal_type=item_portal_type,\n - title=line[\'title\'],\n - reference=line[\'reference\'],\n - quantity=line[\'quantity\'],\n - quantity_unit=context.getQuantityUnit(),\n - **item_property_dict)\n - item.validate()\n + item = context.portal_catalog.getResultValue(\n + portal_type=\'Item\',\n + reference=line[\'reference\'])\n + if item is not None:\n + msg = translateString("Reference Defined On Line ${line_id} already exists",\n + mapping={\'line_id\': line[\'listbox_key\']})\n + raise NotImplementedError(\n + msg)\n + else:\n + module = context.getDefaultModule(item_portal_type)\n + item = module.newContent(portal_type=item_portal_type,\n + title=line[\'title\'],\n + reference=line[\'reference\'],\n + quantity=line[\'quantity\'],\n + quantity_unit=context.getQuantityUnit(),\n + **item_property_dict)\n + item.validate()\n \n line_variation_category_list = []\n for variation in (\n @@ -224,9 +232,11 @@ return context.Base_redirect(form_id, keep_items=dict(\n <string>base_id</string> <string>line</string> <string>None</string> + <string>item</string> + <string>msg</string> + <string>NotImplementedError</string> <string>module</string> <string>_apply_</string> - <string>item</string> <string>line_variation_category_list</string> <string>variation</string> <string>cell_found</string> @@ -237,7 +247,6 @@ return context.Base_redirect(form_id, keep_items=dict(\n <string>movement</string> <string>quantity</string> <string>len</string> - <string>NotImplementedError</string> <string>_inplacevar_</string> </tuple> </value> diff --git a/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts.xml b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts.xml index ef17b83812..0622b3c34f 100644 --- a/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts.xml +++ b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts.xml @@ -15,6 +15,12 @@ <dictionary/> </value> </item> + <item> + <key> <string>_objects</string> </key> + <value> + <tuple/> + </value> + </item> <item> <key> <string>id</string> </key> <value> <string>scripts</string> </value> diff --git a/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts/checkConsistency.xml b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts/checkConsistency.xml new file mode 100644 index 0000000000..ab1278b560 --- /dev/null +++ b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/scripts/checkConsistency.xml @@ -0,0 +1,125 @@ +<?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>object = state_change[\'object\']\n +object.Base_checkConsistency()\n +</string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>state_change</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>1</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>state_change</string> + <string>_getitem_</string> + <string>object</string> + <string>_getattr_</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>checkConsistency</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/transitions/validate_action.xml b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/transitions/validate_action.xml index 1fa3a74ca9..f38c70ef07 100644 --- a/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/transitions/validate_action.xml +++ b/bt5/erp5_item/WorkflowTemplateItem/portal_workflow/item_workflow/transitions/validate_action.xml @@ -45,7 +45,7 @@ </item> <item> <key> <string>script_name</string> </key> - <value> <string></string> </value> + <value> <string>checkConsistency</string> </value> </item> <item> <key> <string>title</string> </key> diff --git a/bt5/erp5_item/bt/revision b/bt5/erp5_item/bt/revision index 2efea5198b..a3090d211b 100644 --- a/bt5/erp5_item/bt/revision +++ b/bt5/erp5_item/bt/revision @@ -1 +1 @@ -167 \ No newline at end of file +168 \ No newline at end of file -- 2.30.9