52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from decimal import Decimal
|
|
|
|
from app.services.pl_transport_stop_feedback_service import (
|
|
PublicStopProductRow,
|
|
_merge_public_stop_products_by_sku,
|
|
)
|
|
|
|
|
|
def _row(**kwargs) -> PublicStopProductRow:
|
|
defaults = dict(
|
|
stop_product_id="sp1",
|
|
plan_product_id="pp1",
|
|
product_id="p1",
|
|
product_name="甲醇",
|
|
model=None,
|
|
unit="吨",
|
|
package_spec="槽罐车",
|
|
delivery_method=None,
|
|
plan_qty=Decimal("10"),
|
|
remark=None,
|
|
actual_qty=Decimal("1"),
|
|
brand_qtys=None,
|
|
)
|
|
defaults.update(kwargs)
|
|
return PublicStopProductRow(**defaults)
|
|
|
|
|
|
def test_merge_same_sku_sums_qty_without_contract_fields():
|
|
rows = [
|
|
_row(stop_product_id="a", plan_qty=Decimal("10"), actual_qty=Decimal("2")),
|
|
_row(stop_product_id="b", plan_qty=Decimal("20"), actual_qty=Decimal("3")),
|
|
]
|
|
merged = _merge_public_stop_products_by_sku(rows)
|
|
assert len(merged) == 1
|
|
assert merged[0].product_id == "p1"
|
|
assert merged[0].package_spec == "槽罐车"
|
|
assert merged[0].plan_qty == Decimal("30")
|
|
assert merged[0].actual_qty == Decimal("5")
|
|
assert not hasattr(merged[0], "contract_id")
|
|
assert not hasattr(merged[0], "contract_product_id")
|
|
|
|
|
|
def test_merge_keeps_different_sku_separate():
|
|
rows = [
|
|
_row(stop_product_id="a", package_spec="槽罐车", plan_qty=Decimal("10")),
|
|
_row(stop_product_id="b", package_spec="25kg/桶", plan_qty=Decimal("5")),
|
|
]
|
|
merged = _merge_public_stop_products_by_sku(rows)
|
|
assert len(merged) == 2
|
|
assert merged[0].plan_qty == Decimal("10")
|
|
assert merged[1].plan_qty == Decimal("5")
|