Files
shanxia2.0/backend/tests/test_pl_brand_archive.py
T
zlwuandCursor 156e4b63e5 fix(pl): treat required brand as preference in brand qty validation
Allow multi-brand feedback/archive rows when plan brandMode is required; only enforce sum equals actual qty.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 06:52:49 +08:00

89 lines
2.7 KiB
Python

from decimal import Decimal
import pytest
from app.services.pl_brand_archive import validate_brand_qty_rows
def test_required_allows_other_brand_when_sum_matches():
validate_brand_qty_rows(
brand_mode="required",
required_brand_id="b1",
actual_qty=Decimal("10"),
rows=[{"brandId": "b2", "brandName": "红四方", "qty": Decimal("10")}],
)
def test_required_allows_multi_brand_when_sum_matches():
validate_brand_qty_rows(
brand_mode="required",
required_brand_id="b1",
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("4")},
],
)
def test_required_sum_must_match():
with pytest.raises(ValueError, match="合计"):
validate_brand_qty_rows(
brand_mode="required",
required_brand_id="b1",
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("3")},
],
)
def test_any_sum_must_match():
with pytest.raises(ValueError, match="合计"):
validate_brand_qty_rows(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("3")},
],
)
def test_any_ok():
validate_brand_qty_rows(
brand_mode="any",
required_brand_id=None,
actual_qty=Decimal("10"),
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("6")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("4")},
],
)
def test_no_brand_ignores_rows():
validate_brand_qty_rows(
brand_mode=None,
required_brand_id=None,
actual_qty=Decimal("5"),
rows=[],
)
def test_apply_stock_change_outbound_insufficient():
from app.services.pl_inventory_service import assert_outbound_enough
with pytest.raises(ValueError, match="库存不足"):
assert_outbound_enough(stock_qty=Decimal("1"), outbound_qty=Decimal("2"), brand_label="君正")
def test_delta_for_plan_type():
from app.services.pl_inventory_service import qty_delta_for_plan
assert qty_delta_for_plan("inbound", Decimal("3")) == Decimal("3")
assert qty_delta_for_plan("outbound", Decimal("3")) == Decimal("-3")
assert qty_delta_for_plan("direct", Decimal("3")) == Decimal("0")