Skip to content

Commit 68461ee

Browse files
authored
fix: remove KWH deposit workaround and deprecate currency-only helpers (#2119)
The financial-accounting posting layer now supports InstrumentAmount for all asset types. Remove the seed script workaround that silently skipped KWH deposits due to 'invalid currency' errors. Mark ParseCurrency and CurrencyToInstrument as deprecated in favour of InstrumentResolver.Resolve() which supports multi-asset instruments. Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 3446aee commit 68461ee

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

cmd/seed-dev/cmd/fixtures.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,25 +388,12 @@ func seedCustomerBalances(ctx context.Context, client currentaccountv1.CurrentAc
388388

389389
// KWH meter read deposit - CREDIT customer kWh account, DEBIT GSP inventory account.
390390
// Uses InstrumentAmount (input field) for non-monetary instruments.
391-
// NOTE: financial-accounting currently only supports ISO-4217 currencies,
392-
// so KWH deposits fail at the posting layer with InvalidArgument. Skip
393-
// that specific error gracefully; propagate unexpected errors (network, auth).
394391
if err := depositInstrumentIdempotent(ctx, client, acct.kwhAccountID, dailyKWH, "KWH",
395392
fmt.Sprintf("Meter read %s: %.2f kWh", date.Format("2006-01-02"), dailyKWH),
396393
fmt.Sprintf("METER-%s-%s", acct.partyID, date.Format("20060102")),
397394
acct.gspKwhAccountID, // GSP inventory account is the debit (clearing) side
398395
); err != nil {
399-
// The saga wraps the financial-accounting rejection as Internal, and the
400-
// inner error is InvalidArgument with "invalid currency". Match on the
401-
// error message to avoid masking unrelated Internal errors.
402-
errMsg := err.Error()
403-
if strings.Contains(errMsg, "invalid currency") || strings.Contains(errMsg, "invalid posting_amount") {
404-
if day == 30 {
405-
fmt.Printf(" [WARN] KWH deposits skipped for %s (financial-accounting does not yet support non-monetary instruments)\n", acct.customerName)
406-
}
407-
} else {
408-
return fmt.Errorf("deposit KWH for %s day %d: %w", acct.customerName, day, err)
409-
}
396+
return fmt.Errorf("deposit KWH for %s day %d: %w", acct.customerName, day, err)
410397
}
411398
}
412399

services/financial-accounting/domain/currency.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func ParseCurrency(s string) (Currency, error) {
3939
// - Precision: derived from the currency's decimal places (e.g., 2 for GBP, 0 for JPY)
4040
//
4141
// Returns an error if the currency is invalid.
42+
//
43+
// Deprecated: Use InstrumentResolver.Resolve() for all new code.
44+
// This function only supports ISO 4217 currencies. For multi-asset support,
45+
// resolve instrument properties from Reference Data via InstrumentResolver.
4246
func CurrencyToInstrument(c Currency) (Instrument, error) {
4347
if !c.IsValid() {
4448
return Instrument{}, ErrInvalidDimension

shared/domain/money/money.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ func (c Currency) DecimalPlaces() int32 {
7979

8080
// ParseCurrency converts a string to a Currency type with validation.
8181
//
82-
// Deprecated: Use shared/pkg/refdata.InstrumentResolver.Resolve() instead.
82+
// Deprecated: Use InstrumentResolver.Resolve() for all new code.
83+
// This function only supports ISO 4217 currencies. For multi-asset support,
84+
// resolve instrument properties from Reference Data via InstrumentResolver.
8385
func ParseCurrency(s string) (Currency, error) {
8486
c := Currency(s)
8587
if !c.IsValid() {

0 commit comments

Comments
 (0)