From 1e3a4213d085d5857203c10c7b2919ad88fc8505 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Sun, 30 Apr 2017 17:09:05 +1000 Subject: [PATCH 1/2] [ENH] - Readonly / Required Dynamic readonly / required on pop-ups need to assume that if they are based on different domain records then they are "or" insted of "and". --- .../wizard/product_configurator.py | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/product_configurator_wizard/wizard/product_configurator.py b/product_configurator_wizard/wizard/product_configurator.py index 5e0055d0..23e3d74a 100644 --- a/product_configurator_wizard/wizard/product_configurator.py +++ b/product_configurator_wizard/wizard/product_configurator.py @@ -443,33 +443,57 @@ def add_dynamic_fields(self, res, dynamic_fields, wiz): # dependee if attr_line.value_ids <= dependencies.mapped('value_ids'): - attr_depends = {} - domain_lines = dependencies.mapped('domain_id.domain_line_ids') - for domain_line in domain_lines: - attr_id = domain_line.attribute_id.id - attr_field = self.field_prefix + str(attr_id) - attr_lines = wiz.product_tmpl_id.attribute_line_ids - # If the fields it depends on are not in the config step - if config_steps and str(attr_line.id) != wiz.state: - continue - if attr_field not in attr_depends: - attr_depends[attr_field] = set() - if domain_line.condition == 'in': - attr_depends[attr_field] |= set( - domain_line.value_ids.ids) - elif domain_line.condition == 'not in': - val_ids = attr_lines.filtered( - lambda l: l.attribute_id.id == attr_id).value_ids - val_ids = val_ids - domain_line.value_ids - attr_depends[attr_field] |= set(val_ids.ids) - - for dependee_field, val_ids in attr_depends.iteritems(): - if not val_ids: - continue - attrs['readonly'].append( - (dependee_field, 'not in', list(val_ids))) - attrs['required'].append( - (dependee_field, 'in', list(val_ids))) + attrs['readonly'] = [] + attrs['required'] = [] + for dependency in dependencies: + this_readonly = [] + this_required = [] + attr_depends = {} + for domain_line in dependency.domain_id.domain_line_ids: + # TODO: Note - THIS STILL ASSUMES "and" + attr_id = domain_line.attribute_id.id + attr_field = self.field_prefix + str(attr_id) + attr_lines = wiz.product_tmpl_id.attribute_line_ids + # If the fields it depends on are not in the config + # step + if config_steps and str(attr_line.id) != wiz.state: + continue + if attr_field not in attr_depends: + attr_depends[attr_field] = set() + if domain_line.condition == 'in': + attr_depends[attr_field] |= set( + domain_line.value_ids.ids) + elif domain_line.condition == 'not in': + val_ids = attr_lines.filtered( + lambda l: l.attribute_id.id == attr_id + ).value_ids + val_ids = val_ids - domain_line.value_ids + attr_depends[attr_field] |= set(val_ids.ids) + + for dependee_field, val_ids in attr_depends.iteritems(): + if not val_ids: + continue + this_readonly.append( + (dependee_field, 'not in', list(val_ids))) + this_required.append( + (dependee_field, 'in', list(val_ids))) + + # Two different dependencies are "or"ed + if this_readonly: + if attrs["readonly"]: + attrs["readonly"][0:0] = ['&'] + # TODO: because of the "and" assumptions within + # one dependency, these work + attrs["readonly"].extend( + (['|'] * (len(this_readonly) - 1)) + this_readonly + ) + if attrs["required"]: + attrs["required"][0:0] = ['|'] + # TODO: because of the "and" assumptions within + # one dependency, these work + attrs["required"].extend( + (['|'] * (len(this_required) - 1)) + this_required + ) # Create the new field in the view node = etree.Element( From 633d391ea4d86afccf83edc90860b0ea21e5c6a2 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Tue, 9 May 2017 09:05:55 +1000 Subject: [PATCH 2/2] PEP8 fix. --- product_configurator_wizard/wizard/product_configurator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product_configurator_wizard/wizard/product_configurator.py b/product_configurator_wizard/wizard/product_configurator.py index 23e3d74a..d36500c4 100644 --- a/product_configurator_wizard/wizard/product_configurator.py +++ b/product_configurator_wizard/wizard/product_configurator.py @@ -486,14 +486,14 @@ def add_dynamic_fields(self, res, dynamic_fields, wiz): # one dependency, these work attrs["readonly"].extend( (['|'] * (len(this_readonly) - 1)) + this_readonly - ) + ) if attrs["required"]: attrs["required"][0:0] = ['|'] # TODO: because of the "and" assumptions within # one dependency, these work attrs["required"].extend( (['|'] * (len(this_required) - 1)) + this_required - ) + ) # Create the new field in the view node = etree.Element(