Commit 48b8c69f authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_administration: Add Scripts for Alarm to update validation state...

erp5_administration: Add Scripts for Alarm to update validation state according to consistency state
parent 36477a37
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>configuration_form_id</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>catalog_query_string</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>module_list</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>lines</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_activateUpdateValidationStateFromConsistencyResult</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>catalog_query_string</string> </key>
<value> <string>validation_state:!=deleted</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>configuration_form_id</string> </key>
<value> <string>Alarm_viewConsistencyCheckConfiguration</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>update_validation_state_from_consistency</string> </value>
</item>
<item>
<key> <string>module_list</string> </key>
<value>
<tuple>
<string>organisation_module</string>
<string>person_module</string>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1230768000.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_week_day</string> </key>
<value>
<tuple>
<string>Sunday</string>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_week_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>report_method_id</string> </key>
<value> <string>Alarm_viewConsistencyCheckReport</string> </value>
</item>
<item>
<key> <string>solve_method_id</string> </key>
<value> <string>Alarm_activateFixConsistency</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Update Validation Consistency Check</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
kw = {}
if context.getProperty('incremental_check'):
last_active_process = context.getLastActiveProcess()
if last_active_process is not None:
kw['indexation_timestamp'] = '>= %s' % last_active_process.getStartDate().ISO()
active_process = context.newActiveProcess().getRelativeUrl()
query_string = context.getProperty('catalog_query_string', '')
# the query sould be something like "validation_state:!=deleted validation_state:!=draft portal_type:Organisation" etc
portal = context.getPortalObject()
if query_string is not None:
kw.update(SearchableText=query_string)
kw.update(parent_uid=[portal.restrictedTraverse(module).getUid() for module in context.getProperty('module_list') or []])
portal.portal_catalog.searchAndActivate(method_id='Base_updateValidationStateFromConsistencyResult', method_kw={'fixit': fixit, 'active_process': active_process}, activate_kw={'tag':tag, 'priority': 8}, **kw)
context.activate(after_tag=tag).getId()
<?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>_params</string> </key>
<value> <string>tag, fixit=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_activateUpdateValidationStateFromConsistencyResult</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Update Validation According to Consistency State</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ERP5Type.Constraint import PropertyTypeValidity
from Products.CMFActivity.ActiveResult import ActiveResult
portal = context.getPortalObject()
constraint_message_list = []
if context.providesIConstraint():
# it is not possible to checkConsistency of Constraint itself, as method
# of this name implement consistency checking on object
return constraint_message_list
missing_category_document = portal.portal_trash.newContent(
portal_type='Missing Category Document Constraint',
temp_object=True)
property_type_validity = PropertyTypeValidity(id='type_check', description='Type Validity Check')
if fixit:
constraint_message_list.extend(context.fixConsistency())
constraint_message_list.extend(property_type_validity.fixConsistency(context))
constraint_message_list.extend(missing_category_document.fixConsistency(context))
else:
constraint_message_list.extend(context.checkConsistency(fixit=fixit))
constraint_message_list.extend(property_type_validity.checkConsistency(context, fixit=fixit))
constraint_message_list.extend(missing_category_document.checkConsistency(context, fixit=fixit))
if constraint_message_list:
portal.restrictedTraverse(active_process).postResult(ActiveResult(severity=100,
constraint_message_list=constraint_message_list))
# Invalidate inconsistent VINs, validate consistent ones, do not consider deleted ones
if context.getValidationState() != "deleted":
if len(constraint_message_list) and context.getValidationState() != "invalidated":
context.invalidate()
elif not len(constraint_message_list) and context.getValidationState() != "validated":
context.validate()
<?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>_params</string> </key>
<value> <string>fixit=None, active_process=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_updateValidationStateFromConsistencyResult</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -114,6 +114,43 @@ class TestERP5Administration(InventoryAPITestCase):
self.tic()
self.assertEqual('3', inconsistent_document.title)
def test_update_validation_from_consistency_alarm(self):
alarm = self.portal.portal_alarms.update_validation_state_from_consistency
inconsistent_document = self.portal.organisation_module.newContent(
portal_type='Organisation')
inconsistent_document.validate()
# this document will be non consistent, for PropertyTypeValidity
inconsistent_document.title = 3
# tic right now to make sure the person is indexed, indeed the alarm
# could use catalog to retrieve objects to check
self.tic()
alarm.activeSense()
self.tic()
# some errors were detected
self.assertTrue(alarm.sense())
# this alarm has a custom report
alarm.Alarm_viewConsistencyCheckReport()
# which has a listbox showing all problem reported by constraints and
# errors reported by property type validity constraint
line_list = alarm.Alarm_viewConsistencyCheckReport.listbox.get_value(
'default', render_format='list')
self.assertEqual(1, len([line for line in line_list if line.isDataLine()]))
self.assertEqual(str(line_list[-1].getColumnProperty('getTranslatedMessage')),
"Attribute title should be of type string but is of type <type 'int'>")
self.assertEqual("invalidated", inconsistent_document.getValidationState())
# this alarm can solve, as long as the constraints can solve, this is the
# case of PropertyTypeValidity
alarm.solve()
self.tic()
self.assertEqual('3', inconsistent_document.title)
alarm.activeSense()
self.tic()
self.assertEqual("validated", inconsistent_document.getValidationState())
def test_check_consistency_incremental(self):
alarm = self.portal.portal_alarms.check_consistency.Base_createCloneDocument(
batch_mode=True)
......
......@@ -5,4 +5,5 @@ portal_alarms/check_folder_handler
portal_alarms/check_item_tracking
portal_alarms/check_localizer
portal_alarms/check_skin_cache
portal_alarms/check_stock
\ No newline at end of file
portal_alarms/check_stock
portal_alarms/update_validation_state_from_consistency
\ 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