Commit b7cc8ef9 authored by Jérome Perrin's avatar Jérome Perrin

Constraints on currencies instead of required fields

We have this [Do Not Test Required In Field View Form](https://www.erp5.com/documentation/developer/guideline/module/erp5-Guideline.Module.Creation#do-not-test-required-in-field-view-form rule) rule:
> This kind of constraint should be defined in Constraints documents and should to be checked in workflow transitions.
>
> Checking a field as "required" can cause problems like not saving the data when the user clicks on the save button. The same applies to the use of External Validators scripts in fields.

Currency view was not respecting this, there was both required fields and external validator. 
Also, the external validator was using an incorrect way of getting the "context document", so it was not working on RenderJS UI.

We are removing required fields and validator here, because this should be implemented using constraints instead.  To somehow preserve the same behavior, a new constraint is added in `erp5_base` and enabled in `erp5_configurator_standard`. Custom projects probably want to enable this constraint, but (as far as I know) we don't enable constraint by default. 

This  `Base_uniqueReferenceInFolderValidator` was apparently not used anywhere else and not working anymore, so we are just removing it.


/reviewed-on nexedi/erp5!710
parents 1e1e2e5a 048fd075
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>CurrencyConstraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Existence Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>constraint_property</string> </key>
<value>
<tuple>
<string>reference</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>reference_existence_constraint</string> </value>
</item>
<item>
<key> <string>message_no_such_property</string> </key>
<value> <string>Reference must be defined</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Existence Constraint</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Attribute Unicity Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>filter_parameter</string> </key>
<value> <string>python: {\'portal_type\': (\'Currency\', ), \'validation_state\': (\'validated\', ),\'reference\': object.getReference()}</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>reference_unicity_constraint</string> </value>
</item>
<item>
<key> <string>message_invalid_attribute_unicity</string> </key>
<value> <string>Another currency with reference ${value} already exists</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Attribute Unicity Constraint</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,10 +10,8 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>description</string>
<string>external_validator</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
......@@ -86,12 +84,6 @@
<key> <string>description</string> </key>
<value> <string>ISO code of the currency or something similar</string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
......@@ -100,10 +92,6 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......@@ -118,23 +106,4 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Products.Formulator.MethodField</string>
<string>Method</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>method_name</string> </key>
<value> <string>Base_uniqueReferenceInFolderValidator</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,9 +10,8 @@
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
<string>description</string>
<string>required</string>
<string>title</string>
</list>
</value>
</item>
......@@ -85,10 +84,6 @@
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......
CurrencyConstraint
LoginConstraint
PreviousCausalityMovementGroup
TemplateToolERP5LoginUserManagerConstraint
\ No newline at end of file
......@@ -25,3 +25,7 @@ for portal_type in ['Purchase Order Line', 'Sale Order Line','Sale Packing List
configuration_save.addConfigurationItem("Portal Type Configurator Item",
target_portal_type='Inventory',
add_propertysheet_list=('InventoryConstraint',))
configuration_save.addConfigurationItem("Portal Type Configurator Item",
target_portal_type='Currency',
add_propertysheet_list=('CurrencyConstraint',))
......@@ -912,27 +912,14 @@ class StandardConfigurationMixin(TestLiveConfiguratorWorkflowMixin):
"""
Configurator can configure some PropertySheets.
"""
portal = self.portal
purchase_order = portal.portal_types['Purchase Order']
purchase_order_line = portal.portal_types['Purchase Order Line']
sale_order = portal.portal_types['Sale Order']
sale_order_line = portal.portal_types['Sale Order Line']
inventory = portal.portal_types['Inventory']
sale_packing_list = portal.portal_types['Sale Packing List']
sale_packing_list_line = portal.portal_types['Sale Packing List Line']
self.assertEqual(True,
'TradeOrderLine' in sale_packing_list_line.getTypePropertySheetList())
self.assertEqual(True,
'TradeOrder' in purchase_order.getTypePropertySheetList())
self.assertEqual(True,
'TradeOrderLine' in purchase_order_line.getTypePropertySheetList())
self.assertEqual(True,
'TradeOrder' in sale_order.getTypePropertySheetList())
self.assertEqual(True,
'TradeOrderLine' in sale_order_line.getTypePropertySheetList())
self.assertEqual(True,
'InventoryConstraint' in inventory.getTypePropertySheetList())
portal_types = self.portal.portal_types
self.assertIn('TradeOrderLine', portal_types['Sale Packing List Line'].getTypePropertySheetList())
self.assertIn('TradeOrder', portal_types['Purchase Order'].getTypePropertySheetList())
self.assertIn('TradeOrderLine', portal_types['Purchase Order Line'].getTypePropertySheetList())
self.assertIn('TradeOrder', portal_types['Sale Order'].getTypePropertySheetList())
self.assertIn('TradeOrderLine', portal_types['Sale Order Line'].getTypePropertySheetList())
self.assertIn('InventoryConstraint', portal_types['Inventory'].getTypePropertySheetList())
self.assertIn('CurrencyConstraint', portal_types['Currency'].getTypePropertySheetList())
def stepCheckSaleOrderSimulation(self, sequence=None, sequence_list=None, **kw):
"""
......
"""Check the object have an unique reference in it's parent folder
"""
from Products.ERP5Type.Log import log
if editor is None :
return 1
reference = editor
document = context.restrictedTraverse(request.object_path, None)
if document is None :
log('Base_uniqueReferenceInFolderValidator', 'document is None')
return 0
parent_folder = document.getParentValue()
for same_reference in parent_folder.searchFolder(reference = reference):
if same_reference.uid != document.getUid() :
log('Base_uniqueReferenceInFolderValidator',
'another document with reference %s exists at %s' % (reference, same_reference.getPath()))
return 0
return 1
<?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>editor, request</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_uniqueReferenceInFolderValidator</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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