fix(crm): 被引用合同明细的空品牌与不限品牌视为同一身份。

编辑页会把历史空品牌提交为 any,原先被当成更换产品身份,导致无法同时新增明细。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-18 20:33:48 +08:00
1 parent d333e97bec
commit 90fc25f3fe
2 files changed
+36 -2

No files matched your search

@@ -309,6 +309,34 @@ def test_referenced_line_still_cannot_change_product_identity_or_be_removed(db):
assert old.del_flag == 0
def test_referenced_blank_brand_can_save_as_unrestricted_and_add_line(db):
"""编辑页把历史空品牌提交为不限品牌时,不算更换身份,可以同时新增明细。"""
old = _referenced_contract(db)
old.brand_mode = None
old.brand_id = None
old.brand_name = None
db.flush()
sync(db, 'contract', [
{'id': 'old', 'brandMode': 'any', 'brandId': None, 'brandName': None},
{'productId': 'lye30', 'productName': '30%液碱', 'model': '30%', 'unit': '吨', 'quantity': 0, 'packageSpec': '槽罐车'},
])
assert old.del_flag == 0 and old.id == 'old' and old.product_id == 'sku'
assert old.brand_mode == 'any' and old.brand_id is None
added = db.query(CrmContractProduct).filter_by(product_id='lye30', del_flag=0).one()
assert added.model == '30%' and added.unit == '吨'
def test_referenced_blank_brand_still_cannot_become_specific_brand(db):
old = _referenced_contract(db)
old.brand_mode = None
old.brand_id = None
old.brand_name = None
db.flush()
with pytest.raises(ValueError, match='不能删除或更换产品身份'):
sync(db, 'contract', [{'id': 'old', 'brandMode': 'required', 'brandId': 'hong', 'brandName': '红四方'}])
assert old.brand_mode is None and old.brand_id is None and old.del_flag == 0
@pytest.mark.parametrize('follow_status,delivery_flag', [('cancelled', 0), ('arranged', 1)])
def test_inactive_plan_reference_does_not_lock_package_spec(db, follow_status, delivery_flag):
old = _referenced_contract(db, follow_status=follow_status, delivery_flag=delivery_flag)