fixed ledger account listing + quotation listing

This commit is contained in:
Stephan D
2026-01-23 02:48:10 +01:00
parent 218c4e20b3
commit 41f653775f
60 changed files with 469 additions and 283 deletions

View File

@@ -14,8 +14,10 @@ class LedgerAccountDTO {
final String organizationRef;
final String? ownerRef;
final String accountCode;
@JsonKey(fromJson: ledgerAccountTypeFromJson, toJson: ledgerAccountTypeToJson)
final LedgerAccountTypeDTO accountType;
final String currency;
@JsonKey(fromJson: ledgerAccountStatusFromJson, toJson: ledgerAccountStatusToJson)
final LedgerAccountStatusDTO status;
final bool allowNegative;
final bool isSettlement;
@@ -23,7 +25,7 @@ class LedgerAccountDTO {
final DateTime? createdAt;
final DateTime? updatedAt;
final DescribableDTO describable;
final DescribableDTO? describable;
final LedgerBalanceDTO? balance;
@@ -40,7 +42,7 @@ class LedgerAccountDTO {
this.metadata,
this.createdAt,
this.updatedAt,
required this.describable,
this.describable,
this.balance,
});

View File

@@ -11,3 +11,34 @@ enum LedgerAccountStatusDTO {
@JsonValue('frozen')
frozen,
}
LedgerAccountStatusDTO ledgerAccountStatusFromJson(Object? value) {
final raw = value?.toString() ?? '';
var normalized = raw.trim().toLowerCase();
const prefix = 'account_status_';
if (normalized.startsWith(prefix)) {
normalized = normalized.substring(prefix.length);
}
switch (normalized) {
case 'active':
return LedgerAccountStatusDTO.active;
case 'frozen':
return LedgerAccountStatusDTO.frozen;
case 'unspecified':
case '':
return LedgerAccountStatusDTO.unspecified;
default:
return LedgerAccountStatusDTO.unspecified;
}
}
String ledgerAccountStatusToJson(LedgerAccountStatusDTO value) {
switch (value) {
case LedgerAccountStatusDTO.active:
return 'active';
case LedgerAccountStatusDTO.frozen:
return 'frozen';
case LedgerAccountStatusDTO.unspecified:
return 'unspecified';
}
}

View File

@@ -17,3 +17,42 @@ enum LedgerAccountTypeDTO {
@JsonValue('expense')
expense,
}
LedgerAccountTypeDTO ledgerAccountTypeFromJson(Object? value) {
final raw = value?.toString() ?? '';
var normalized = raw.trim().toLowerCase();
const prefix = 'account_type_';
if (normalized.startsWith(prefix)) {
normalized = normalized.substring(prefix.length);
}
switch (normalized) {
case 'asset':
return LedgerAccountTypeDTO.asset;
case 'liability':
return LedgerAccountTypeDTO.liability;
case 'revenue':
return LedgerAccountTypeDTO.revenue;
case 'expense':
return LedgerAccountTypeDTO.expense;
case 'unspecified':
case '':
return LedgerAccountTypeDTO.unspecified;
default:
return LedgerAccountTypeDTO.unspecified;
}
}
String ledgerAccountTypeToJson(LedgerAccountTypeDTO value) {
switch (value) {
case LedgerAccountTypeDTO.asset:
return 'asset';
case LedgerAccountTypeDTO.liability:
return 'liability';
case LedgerAccountTypeDTO.revenue:
return 'revenue';
case LedgerAccountTypeDTO.expense:
return 'expense';
case LedgerAccountTypeDTO.unspecified:
return 'unspecified';
}
}

View File

@@ -3,6 +3,7 @@ import 'package:pshared/data/mapper/describable.dart';
import 'package:pshared/data/mapper/ledger/balance.dart';
import 'package:pshared/data/mapper/ledger/status.dart';
import 'package:pshared/data/mapper/ledger/type.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/ledger/account.dart';
@@ -20,7 +21,7 @@ extension LedgerAccountDTOMapper on LedgerAccountDTO {
metadata: metadata,
createdAt: createdAt,
updatedAt: updatedAt,
describable: describable.toDomain(),
describable: describable?.toDomain() ?? newDescribable(name: '', description: null),
balance: balance?.toDomain(),
);
}