From 27dec68fc234b59ff076833cfd458445545454bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Mon, 19 Oct 2026 15:12:09 +0800 Subject: [PATCH] fix(rules): fill blank plan cells from matching explicit rules --- .../trial_task_center/batch_rules.py | 4 +++ tests/v1_1/test_target_cell_rules.py | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/dx_productivity/trial_task_center/batch_rules.py b/src/dx_productivity/trial_task_center/batch_rules.py index 42e1bb6..cdb9772 100644 --- a/src/dx_productivity/trial_task_center/batch_rules.py +++ b/src/dx_productivity/trial_task_center/batch_rules.py @@ -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) diff --git a/tests/v1_1/test_target_cell_rules.py b/tests/v1_1/test_target_cell_rules.py index ae2825e..5d07f8a 100644 --- a/tests/v1_1/test_target_cell_rules.py +++ b/tests/v1_1/test_target_cell_rules.py @@ -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])