From 660ca7a31b464f8cae4d55ea0d0f0dd402ff0a66 Mon Sep 17 00:00:00 2001 From: Fabien Morin <fabien@nexedi.com> Date: Wed, 4 Feb 2009 13:30:00 +0000 Subject: [PATCH] 2009-02-04 fabien * when a specialise model is defined on a paysheet, apply it automatically * rewrite the apply model script git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25445 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../PaySheetTransaction_applyModel.xml | 68 +++++++--- ...Transaction_setSpecialiseAndApplyModel.xml | 127 ++++++++++++++++++ .../my_specialise_title.xml | 5 + bt5/erp5_payroll/bt/change_log | 4 + bt5/erp5_payroll/bt/revision | 2 +- 5 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_setSpecialiseAndApplyModel.xml diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_applyModel.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_applyModel.xml index cebb576bbd..a7a254c490 100644 --- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_applyModel.xml +++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_applyModel.xml @@ -53,9 +53,18 @@ </item> <item> <key> <string>_body</string> </key> - <value> <string>Base_translateString = context.Base_translateString\n + <value> <string encoding="cdata"><![CDATA[ + +Base_translateString = context.Base_translateString\n paysheet = context\n \n +# copy categories\n +category_list = [\n + \'destination_section\', \'source_section\', \'source_payment\',\n + \'destination_payment\', \'price_currency\', \'ressource\',\n +]\n +new_category_dict = {}\n +\n model = paysheet.getSpecialiseValue()\n \n if model is None:\n @@ -73,24 +82,26 @@ def getPropertyFromModel(model, property_name):\n if v:\n return v\n \n -# set source and destination from the model if there is no value yet defined\n -if not paysheet.getDestinationSection():\n - paysheet.setDestinationSection(getPropertyFromModel(model, \'destination_section\'))\n -\n -if not paysheet.getSourceSection():\n - paysheet.setSourceSection(getPropertyFromModel(model, \'source_section\'))\n -\n -if not paysheet.getSourcePayment():\n - paysheet.setSourcePayment(getPropertyFromModel(model, \'source_payment\'))\n -\n -if not paysheet.getDestinationPayment():\n - paysheet.setDestinationPayment(getPropertyFromModel(model, \'destination_payment\'))\n +for category in category_list:\n + if force or not paysheet.getPropertyList(category):\n + v = getPropertyFromModel(model, category)\n + if v:\n + new_category_dict[category] = v\n \n -if not paysheet.getPriceCurrency():\n - paysheet.setPriceCurrency(getPropertyFromModel(model, \'price_currency\'))\n +def copyPaymentCondition(paysheet, model):\n + filter_dict = {\'portal_type\': \'Payment Condition\'}\n + to_copy = model.contentIds(filter=filter_dict)\n + if len(to_copy) > 0 :\n + copy_data = model.manage_copyObjects(ids=to_copy)\n + paysheet.manage_pasteObjects(copy_data)\n + for other_models in model.getSpecialiseValueList():\n + copyPaymentCondition(paysheet, other_models)\n \n -if not paysheet.getResource():\n - paysheet.setResource(getPropertyFromModel(model, \'price_currency\'))\n +filter_dict = {\'portal_type\': \'Payment Condition\'}\n +if force:\n + paysheet.manage_delObjects(list(paysheet.contentIds(filter=filter_dict)))\n +if len(paysheet.contentIds(filter=filter_dict)) == 0:\n + copyPaymentCondition(paysheet, model)\n \n # copy model sub objects into paysheet\n paysheet.PaySheetTransaction_copySubObject(\n @@ -101,10 +112,14 @@ paysheet.PaySheetTransaction_copySubObject(\n property_list=(\'quantity\',))\n paysheet.PaySheetTransaction_copySubObject(\'Payment Condition\')\n \n +paysheet.edit(**new_category_dict)\n +\n if not batch_mode:\n return context.Base_redirect(form_id,\n keep_items=dict(portal_status_message=Base_translateString(\'Pay Sheet Transaction updated.\')))\n -</string> </value> + + +]]></string> </value> </item> <item> <key> <string>_code</string> </key> @@ -114,7 +129,7 @@ if not batch_mode:\n </item> <item> <key> <string>_params</string> </key> - <value> <string>form_id=\'view\', batch_mode=0</string> </value> + <value> <string>form_id=\'view\', batch_mode=0, force=0</string> </value> </item> <item> <key> <string>errors</string> </key> @@ -134,7 +149,7 @@ if not batch_mode:\n <dictionary> <item> <key> <string>co_argcount</string> </key> - <value> <int>2</int> </value> + <value> <int>3</int> </value> </item> <item> <key> <string>co_varnames</string> </key> @@ -142,14 +157,26 @@ if not batch_mode:\n <tuple> <string>form_id</string> <string>batch_mode</string> + <string>force</string> <string>_getattr_</string> <string>context</string> <string>Base_translateString</string> <string>paysheet</string> + <string>category_list</string> + <string>new_category_dict</string> <string>model</string> <string>None</string> <string>dict</string> <string>getPropertyFromModel</string> + <string>_getiter_</string> + <string>category</string> + <string>v</string> + <string>_write_</string> + <string>copyPaymentCondition</string> + <string>filter_dict</string> + <string>list</string> + <string>len</string> + <string>_apply_</string> </tuple> </value> </item> @@ -164,6 +191,7 @@ if not batch_mode:\n <tuple> <string>view</string> <int>0</int> + <int>0</int> </tuple> </value> </item> diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_setSpecialiseAndApplyModel.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_setSpecialiseAndApplyModel.xml new file mode 100644 index 0000000000..54ffdab71a --- /dev/null +++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_setSpecialiseAndApplyModel.xml @@ -0,0 +1,127 @@ +<?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>context.setSpecialiseUidList(relation_uid_list, portal_type=portal_type)\n +\n +if relation_uid_list:\n + context.PaySheetTransaction_applyModel(force=1)\n +</string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>relation_uid_list, portal_type</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>2</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>relation_uid_list</string> + <string>portal_type</string> + <string>_getattr_</string> + <string>context</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>PaySheetTransaction_setSpecialiseAndApplyModel</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_specialise_title.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_specialise_title.xml index 5e877e5d02..f73d1461e5 100644 --- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_specialise_title.xml +++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_specialise_title.xml @@ -18,6 +18,7 @@ <string>base_category</string> <string>portal_type</string> <string>catalog_index</string> + <string>relation_setter_id</string> </list> </value> </item> @@ -133,6 +134,10 @@ <key> <string>read_only</string> </key> <value> <int>0</int> </value> </item> + <item> + <key> <string>relation_setter_id</string> </key> + <value> <string>PaySheetTransaction_setSpecialiseAndApplyModel</string> </value> + </item> <item> <key> <string>target</string> </key> <value> <string>Click to edit the target</string> </value> diff --git a/bt5/erp5_payroll/bt/change_log b/bt5/erp5_payroll/bt/change_log index c3ab85b0e4..234bb9b0f4 100644 --- a/bt5/erp5_payroll/bt/change_log +++ b/bt5/erp5_payroll/bt/change_log @@ -1,3 +1,7 @@ +2009-02-04 fabien +* when a specialise model is defined on a paysheet, apply it automatically +* rewrite the apply model script + 2009-01-28 fabien * remove some unused script and refeactor some very similar scripts in a generic one diff --git a/bt5/erp5_payroll/bt/revision b/bt5/erp5_payroll/bt/revision index 387c46fdec..6ffe0d0bf6 100644 --- a/bt5/erp5_payroll/bt/revision +++ b/bt5/erp5_payroll/bt/revision @@ -1 +1 @@ -346 \ No newline at end of file +348 \ No newline at end of file -- 2.30.9