43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""build_plan_product 应支持传入 product_row_id,编辑时保持 pl_plan_product.id 稳定。"""
|
|
from app.schemas.pl.plan import PlanProductCreate
|
|
from app.services import pl_plan_service as svc
|
|
from app.services.pl_plan_service import build_plan_product
|
|
|
|
|
|
def _minimal_prod(**kwargs) -> PlanProductCreate:
|
|
data = {
|
|
"product_id": "crm-p1",
|
|
"product_no": "P001",
|
|
"product_name": "甲醇",
|
|
}
|
|
data.update(kwargs)
|
|
return PlanProductCreate(**data)
|
|
|
|
|
|
def test_build_plan_product_keeps_row_id():
|
|
result = build_plan_product(
|
|
tenant_no="t1",
|
|
plan_id="plan-1",
|
|
plan_type="outbound",
|
|
prod=_minimal_prod(),
|
|
order_num=0,
|
|
user_id="u1",
|
|
dept_id="d1",
|
|
product_row_id="pp-1",
|
|
)
|
|
assert result.id == "pp-1"
|
|
|
|
|
|
def test_build_plan_product_generates_when_missing(monkeypatch):
|
|
monkeypatch.setattr(svc, "generate_uuid", lambda: "gen-1")
|
|
result = build_plan_product(
|
|
tenant_no="t1",
|
|
plan_id="plan-1",
|
|
plan_type="outbound",
|
|
prod=_minimal_prod(),
|
|
order_num=0,
|
|
user_id="u1",
|
|
dept_id="d1",
|
|
)
|
|
assert result.id == "gen-1"
|