fix(pl): clear plan-cert conversion queue after saved ratio or waiver
证书齐备豁免或已填写完整人工换算的计划不再标「需单位换算」,避免已归档豁免单长期挂在待办列表。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8bffb1cbf5
commit
85f5f29895
2 files changed
+92
-23
No files matched your search
@@ -23,47 +23,77 @@ def line(line_id, side, unit, contract_product_id='cp', customer='客户', toxic
|
||||
}
|
||||
|
||||
|
||||
def bind(unit, kind='purchase', cert_id='buy'):
|
||||
return {'kind': kind, 'certId': cert_id, 'unit': unit}
|
||||
|
||||
|
||||
def plan(**values):
|
||||
return SimpleNamespace(
|
||||
cert_configuration=values.get('configuration'),
|
||||
transport_status=values.get('transport_status', 'pending'),
|
||||
archive_status=values.get('archive_status', 'unarchived'),
|
||||
quota_cert_waived=values.get('quota_cert_waived', 0),
|
||||
)
|
||||
|
||||
|
||||
def test_same_label_and_code_do_not_need_conversion():
|
||||
current = plan()
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨')], {'cp': ['dun']}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨', toxic=False)], {'cp': ['kg']}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨')], {'cp': [bind('dun')]}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨', toxic=False)], {'cp': [bind('kg')]}, []) is False
|
||||
assert plan_needs_unit_conversion(
|
||||
current, [line('L', 'load', '吨', customer='安庆市山峡化工有限公司')], {'cp': ['ping']}, [],
|
||||
current, [line('L', 'load', '吨', customer='安庆市山峡化工有限公司')], {'cp': [bind('ping')]}, [],
|
||||
) is True
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨')], {'cp': ['kg']}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '升')], {'cp': ['毫升']}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '吨')], {'cp': [bind('kg')]}, []) is False
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', '升')], {'cp': [bind('毫升')]}, []) is False
|
||||
|
||||
|
||||
def test_unbound_and_unselected_legacy_sides_are_display_only():
|
||||
both = [line('L', 'load', '吨'), line('D', 'delivery', '吨')]
|
||||
arranged = plan(transport_status='arranged')
|
||||
assert plan_needs_unit_conversion(arranged, both, {'cp': ['kg']}, []) is False
|
||||
assert plan_needs_unit_conversion(arranged, both, {'cp': [bind('kg')]}, []) is False
|
||||
chosen = plan(transport_status='arranged', configuration={'sourceMapping': [
|
||||
{'sourceStopType': 'load', 'sourceStopProductId': 'L', 'relatedStopProductIds': ['D']},
|
||||
]})
|
||||
assert plan_needs_unit_conversion(chosen, both, {'cp': ['瓶']}, []) is True
|
||||
assert plan_needs_unit_conversion(chosen, both, {'cp': ['kg']}, []) is False
|
||||
assert plan_needs_unit_conversion(chosen, both, {'cp': [bind('瓶')]}, []) is True
|
||||
assert plan_needs_unit_conversion(chosen, both, {'cp': [bind('kg')]}, []) is False
|
||||
|
||||
|
||||
def test_new_plan_counts_either_stop_when_a_bound_certificate_uses_another_unit():
|
||||
current = plan()
|
||||
assert plan_needs_unit_conversion(
|
||||
current, [line('L', 'load', 'dun'), line('D', 'delivery', 'dun')], {'cp': ['kg']}, [],
|
||||
current, [line('L', 'load', 'dun'), line('D', 'delivery', 'dun')], {'cp': [bind('kg')]}, [],
|
||||
) is False
|
||||
assert plan_needs_unit_conversion(
|
||||
current, [line('L', 'load', 'dun'), line('D', 'delivery', 'dun')], {'cp': ['ping']}, [],
|
||||
current, [line('L', 'load', 'dun'), line('D', 'delivery', 'dun')], {'cp': [bind('ping')]}, [],
|
||||
) is True
|
||||
assert plan_needs_unit_conversion(current, [line('L', 'load', 'dun')], {}, []) is False
|
||||
|
||||
|
||||
def test_waived_or_saved_manual_conversion_clears_pending_flag():
|
||||
current = plan(quota_cert_waived=1)
|
||||
assert plan_needs_unit_conversion(
|
||||
current, [line('L', 'load', 'ping')], {'cp': [bind('sheng', cert_id='buy')]}, [],
|
||||
) is False
|
||||
saved = plan(configuration={
|
||||
'manualAllocations': [{
|
||||
'permitKind': 'purchase', 'sourceId': 'delivery:D', 'permitId': 'buy',
|
||||
'sourceQuantity': '10', 'permitQuantity': '2.5', 'note': '1瓶=0.25升',
|
||||
}],
|
||||
})
|
||||
assert plan_needs_unit_conversion(
|
||||
saved, [line('D', 'delivery', 'ping')], {'cp': [bind('sheng', cert_id='buy')]}, [],
|
||||
) is False
|
||||
incomplete = plan(configuration={
|
||||
'manualAllocations': [{
|
||||
'permitKind': 'purchase', 'sourceId': 'delivery:D', 'permitId': 'buy',
|
||||
'sourceQuantity': '10', 'permitQuantity': '', 'note': '',
|
||||
}],
|
||||
})
|
||||
assert plan_needs_unit_conversion(
|
||||
incomplete, [line('D', 'delivery', 'ping')], {'cp': [bind('sheng', cert_id='buy')]}, [],
|
||||
) is True
|
||||
|
||||
|
||||
def test_list_and_badge_count_only_plans_with_a_real_unit_mismatch(monkeypatch):
|
||||
engine = create_engine('sqlite://')
|
||||
models = (
|
||||
|
||||
Reference in new issue
Block a user