fix(rules): fill blank plan cells from matching explicit rules
This commit is contained in:
1 parent
cf671a1d3f
commit
27dec68fc2
2 files changed
+37
No files matched your search
@@ -91,6 +91,10 @@ def _propagate(store, task_id, before, after):
|
||||
changes['sync_nc'] = rule.sync_nc
|
||||
if not row.custom_value_enabled and not row.custom_value:
|
||||
changes.update(custom_value_enabled=rule.custom_value_enabled, custom_value=rule.custom_value)
|
||||
if (not changes.get('target_cell', row.target_cell)
|
||||
and changes.get('new_part_number', row.new_part_number) == rule.new_part_number):
|
||||
# Saved BOM/manual mappings can predate their explicit rule Cell.
|
||||
changes['target_cell'] = rule.target_cell
|
||||
updated.append(replace(row, **changes))
|
||||
if tuple(updated) != rows:
|
||||
store.replace_target_plan(task_id, updated)
|
||||
|
||||
@@ -273,3 +273,36 @@ def test_update_rejects_non_text_cell_instead_of_clearing(batch):
|
||||
with pytest.raises(TaskCenterError):
|
||||
app.update_rule(rule.rule_id, old_part_number='OLD', new_part_number='NEW', enabled=True, target_cell=0)
|
||||
assert app.rules(tasks[0].task_id)[0].target_cell == 'Existing'
|
||||
|
||||
|
||||
def test_matching_rule_can_fill_blank_cell_after_bom_plan_was_saved(batch):
|
||||
app,store,tasks=batch
|
||||
task=tasks[0];target=target_for(store,task)
|
||||
store.record_target_inventory(task.task_id,(target,))
|
||||
store.replace_target_plan(task.task_id,(TargetPlanRow(target,True,'NEW',custom_value_enabled=True,custom_value='MANUAL',sync_nc=False),))
|
||||
app.add_rule(task.task_id,'OLD','NEW',target_cell='CellA')
|
||||
row=app.target_plan(task.task_id)[0]
|
||||
assert row.target_cell=='CellA'
|
||||
assert (row.new_part_number,row.custom_value_enabled,row.custom_value,row.sync_nc,row.enabled)==('NEW',True,'MANUAL',False,True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('operation', ['add', 'update'])
|
||||
def test_matching_rule_fills_only_blank_cells_and_preserves_manual_plan_options(batch, operation):
|
||||
app, store, tasks = batch
|
||||
task = tasks[0]
|
||||
rule = app.add_rule(task.task_id, 'OLD', 'INITIAL', target_cell='InitialCell') if operation == 'update' else None
|
||||
target = target_for(store, task)
|
||||
targets = tuple(replace(target, uid=f'uid{i}', refdes=f'R{i}') for i in range(1, 4))
|
||||
store.record_target_inventory(task.task_id, targets)
|
||||
rows = (
|
||||
TargetPlanRow(targets[0], False, 'NEW', True, 'custom blank', False),
|
||||
TargetPlanRow(targets[1], True, 'NEW', True, 'custom independent', False, 'IndependentCell'),
|
||||
TargetPlanRow(targets[2], True, 'UNRELATED', True, 'custom unrelated', False),
|
||||
)
|
||||
store.replace_target_plan(task.task_id, rows)
|
||||
if operation == 'add':
|
||||
app.add_rule(task.task_id, 'OLD', 'NEW', target_cell='CellA')
|
||||
else:
|
||||
app.update_rule(rule.rule_id, old_part_number='OLD', new_part_number='NEW', enabled=True, target_cell='CellA')
|
||||
actual = app.target_plan(task.task_id)
|
||||
assert actual == (replace(rows[0], target_cell='CellA'), rows[1], rows[2])
|
||||
Reference in new issue
Block a user