Skip to content

Commit 6b6cab4

Browse files
kitallisclaude
andcommitted
Fix item subtotal formatting when subtotalDisplay is missing
Format numeric amounts properly with currency symbol instead of showing raw Go type annotation like %!s(float64=1001) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d2fd7f4 commit 6b6cab4

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ func formatQuoteMessage(data QuoteData, live bool, title string) SlackMessage {
427427
if len(data.Items) > 0 {
428428
text += "\n\nItems:"
429429
for _, item := range data.Items {
430-
subtotalStr := fmt.Sprintf("%v", item.Subtotal)
431-
if item.SubtotalDisplay != "" {
432-
subtotalStr = item.SubtotalDisplay
430+
subtotalStr := item.SubtotalDisplay
431+
if subtotalStr == "" {
432+
subtotalStr = formatAnyAmount(item.Subtotal, data.QuoteCurrency)
433433
}
434434
text += fmt.Sprintf("\n• %s (x%v) - %s", item.Display, item.Quantity, subtotalStr)
435435
}
@@ -446,6 +446,26 @@ func formatCurrency(amount any, currency string) string {
446446
return fmt.Sprintf("%s %v", currency, amount)
447447
}
448448

449+
func formatAnyAmount(amount any, currency string) string {
450+
switch v := amount.(type) {
451+
case float64:
452+
if currency != "" {
453+
return fmt.Sprintf("%s %.2f", currency, v)
454+
}
455+
return fmt.Sprintf("%.2f", v)
456+
case string:
457+
if currency != "" && v != "" {
458+
return fmt.Sprintf("%s %s", currency, v)
459+
}
460+
return v
461+
default:
462+
if currency != "" {
463+
return fmt.Sprintf("%s %v", currency, amount)
464+
}
465+
return fmt.Sprintf("%v", amount)
466+
}
467+
}
468+
449469
func sendSlackNotification(message SlackMessage) error {
450470
webhookURL := os.Getenv("SLACK_WEBHOOK_URL")
451471
if webhookURL == "" {

0 commit comments

Comments
 (0)