fix: 样本上的空运费按空返回,避免顺丰月结显示成 0
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dd00dba39c
commit
d67965aae2
2 files changed
+34
-6
No files matched your search
@@ -1037,6 +1037,21 @@ def delete_freight(
|
||||
}
|
||||
|
||||
|
||||
def freight_amount_payload(
|
||||
amount: Any, transport_mode: Optional[str], money_as_string: bool
|
||||
) -> Dict[str, Any]:
|
||||
if amount is None:
|
||||
freight_amount: Any = None
|
||||
elif money_as_string:
|
||||
freight_amount = format(Decimal(str(amount)).quantize(Decimal("0.01")), "f")
|
||||
else:
|
||||
freight_amount = float(amount)
|
||||
return {
|
||||
"freightAmount": freight_amount,
|
||||
"freightAmountLabel": freight_amount_label(transport_mode, amount),
|
||||
}
|
||||
|
||||
|
||||
def freight_map_for_samples(
|
||||
db: Session,
|
||||
*,
|
||||
@@ -1089,13 +1104,11 @@ def freight_map_for_samples(
|
||||
"transportModeLabel": labels.get(
|
||||
freight.transport_mode or "", freight.transport_mode or ""
|
||||
),
|
||||
"freightAmount": (
|
||||
format(Decimal(str(freight.freight_amount)).quantize(Decimal('0.01')), 'f')
|
||||
if money_as_string and freight.freight_amount is not None
|
||||
else float(freight.freight_amount)
|
||||
if freight.freight_amount is not None
|
||||
else '0.00' if money_as_string else 0.0
|
||||
**freight_amount_payload(
|
||||
freight.freight_amount, freight.transport_mode, money_as_string
|
||||
),
|
||||
"waybillNo": getattr(freight, "waybill_no", None) or "",
|
||||
"settleStatus": getattr(freight, "settle_status", None) or "",
|
||||
"linkedSampleCount": count_map.get(freight.id, 0),
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -211,3 +211,18 @@ def test_amount_serializer_keeps_null_instead_of_zero():
|
||||
assert admin["freightAmountLabel"] == "月结"
|
||||
assert market["freightAmount"] is None
|
||||
assert market["freightAmountLabel"] == "月结"
|
||||
|
||||
|
||||
def test_sample_card_payload_keeps_null_amount():
|
||||
from app.crud.sample_freight import freight_amount_payload
|
||||
|
||||
monthly = freight_amount_payload(None, "sfkd", True)
|
||||
assert monthly["freightAmount"] is None
|
||||
assert monthly["freightAmountLabel"] == "月结"
|
||||
assert freight_amount_payload(None, "sfkd", False)["freightAmount"] is None
|
||||
assert freight_amount_payload(None, "zxc", True)["freightAmountLabel"] == ""
|
||||
|
||||
numeric = freight_amount_payload(Decimal("88"), "zxc", True)
|
||||
assert numeric["freightAmount"] == "88.00"
|
||||
assert numeric["freightAmountLabel"] == "88.00"
|
||||
assert freight_amount_payload(Decimal("0"), "zxc", False)["freightAmount"] == 0.0
|
||||
Reference in new issue
Block a user