ledger accounts improvement
This commit is contained in:
@@ -20,13 +20,6 @@ const (
|
||||
AccountTypeExpense AccountType = "expense"
|
||||
)
|
||||
|
||||
type AccountStatus string
|
||||
|
||||
const (
|
||||
AccountStatusActive AccountStatus = "active"
|
||||
AccountStatusFrozen AccountStatus = "frozen"
|
||||
)
|
||||
|
||||
// lowercase a-z0-9 segments separated by ':'
|
||||
var accountKeyRe = regexp.MustCompile(`^[a-z0-9]+(?:[:][a-z0-9]+)*$`)
|
||||
|
||||
@@ -45,15 +38,14 @@ type Account struct {
|
||||
OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"`
|
||||
|
||||
// Posting policy & lifecycle
|
||||
AllowNegative bool `bson:"allowNegative" json:"allowNegative"`
|
||||
Status AccountStatus `bson:"status" json:"status"`
|
||||
AllowNegative bool `bson:"allowNegative" json:"allowNegative"`
|
||||
Status model.LedgerAccountStatus `bson:"status" json:"status"`
|
||||
Role model.AccountRole `bson:"role,omitempty" json:"role,omitempty"`
|
||||
|
||||
// Legal ownership history
|
||||
Ownerships []Ownership `bson:"ownerships,omitempty" json:"ownerships,omitempty"`
|
||||
CurrentOwners []Ownership `bson:"currentOwners,omitempty" json:"currentOwners,omitempty"` // denormalized cache
|
||||
|
||||
// Operational flags
|
||||
IsSettlement bool `bson:"isSettlement,omitempty" json:"isSettlement,omitempty"`
|
||||
}
|
||||
|
||||
func (a *Account) NormalizeKey() {
|
||||
@@ -79,9 +71,27 @@ func (a *Account) Validate() error {
|
||||
}
|
||||
|
||||
switch a.Status {
|
||||
case AccountStatusActive, AccountStatusFrozen:
|
||||
case model.LedgerAccountStatusActive, model.LedgerAccountStatusFrozen, model.LedgerAccountStatusClosed:
|
||||
default:
|
||||
veAdd(&verr, "status", "invalid", "expected active|frozen")
|
||||
veAdd(&verr, "status", "invalid", "expected active|frozen|closed")
|
||||
}
|
||||
|
||||
if role := strings.TrimSpace(string(a.Role)); role != "" {
|
||||
switch a.Role {
|
||||
case model.AccountRoleOperating,
|
||||
model.AccountRoleHold,
|
||||
model.AccountRoleTransit,
|
||||
model.AccountRoleSettlement,
|
||||
model.AccountRoleClearing,
|
||||
model.AccountRolePending,
|
||||
model.AccountRoleReserve,
|
||||
model.AccountRoleLiquidity,
|
||||
model.AccountRoleFee,
|
||||
model.AccountRoleChargeback,
|
||||
model.AccountRoleAdjustment:
|
||||
default:
|
||||
veAdd(&verr, "role", "invalid", "unknown account role")
|
||||
}
|
||||
}
|
||||
|
||||
// Validate ownership arrays with index context
|
||||
|
||||
Reference in New Issue
Block a user