|
|
@@ -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
|