Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
[ENH] - Readonly / Required
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
Richard deMeester committed May 5, 2017
1 parent 89750da commit 1e3a421
Showing 1 changed file with 51 additions and 27 deletions.
78 changes: 51 additions & 27 deletions product_configurator_wizard/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1e3a421

Please sign in to comment.