+ ledger account ownerRef

This commit is contained in:
Stephan D
2026-01-22 00:38:05 +01:00
parent eb4e7bc06a
commit 62ff96b90e
31 changed files with 69 additions and 47 deletions

View File

@@ -9,7 +9,7 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/stretchr/testify v1.11.1
github.com/tech/sendico/pkg v0.1.0
go.mongodb.org/mongo-driver v1.17.6
go.mongodb.org/mongo-driver v1.17.7
go.uber.org/zap v1.27.1
google.golang.org/grpc v1.78.0
google.golang.org/protobuf v1.36.11

View File

@@ -152,8 +152,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=
go.mongodb.org/mongo-driver v1.17.6/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
go.mongodb.org/mongo-driver v1.17.7 h1:a9w+U3Vt67eYzcfq3k/OAv284/uUUkL0uP75VE5rCOU=
go.mongodb.org/mongo-driver v1.17.7/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=

View File

@@ -76,6 +76,15 @@ func (s *Service) createAccountResponder(_ context.Context, req *ledgerv1.Create
describable := describableFromProto(req.GetDescribable())
var ownerRef *primitive.ObjectID
if req.GetOwnerRef() != "" {
ownerObjID, err := parseObjectID(req.GetOwnerRef())
if err != nil {
return nil, merrors.InvalidArgument(req.GetOwnerRef(), "owner_ref")
}
ownerRef = &ownerObjID
}
account := &model.Account{
AccountCode: accountCode,
Currency: currency,
@@ -84,6 +93,7 @@ func (s *Service) createAccountResponder(_ context.Context, req *ledgerv1.Create
AllowNegative: req.GetAllowNegative(),
IsSettlement: req.GetIsSettlement(),
Metadata: metadata,
OwnerRef: ownerRef,
}
if describable != nil {
account.Describable = *describable
@@ -209,9 +219,15 @@ func toProtoAccount(account *model.Account) *ledgerv1.LedgerAccount {
metadata = nil
}
var ownerRef string
if account.OwnerRef != nil && !account.OwnerRef.IsZero() {
ownerRef = account.OwnerRef.Hex()
}
return &ledgerv1.LedgerAccount{
LedgerAccountRef: accountRef,
OrganizationRef: organizationRef,
OwnerRef: ownerRef,
AccountCode: account.AccountCode,
AccountType: modelAccountTypeToProto(account.AccountType),
Currency: account.Currency,

View File

@@ -89,6 +89,7 @@ func (c *connectorAdapter) OpenAccount(ctx context.Context, req *connectorv1.Ope
IsSettlement: reader.Bool("is_settlement"),
Metadata: metadata,
Describable: describable,
OwnerRef: req.GetOwnerRef(),
})
if err != nil {
return &connectorv1.OpenAccountResponse{Error: connectorError(mapErrorCode(err), err.Error(), nil, "")}, nil

View File

@@ -3,6 +3,7 @@ package model
import (
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/model"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Account represents a ledger account that holds balances for a specific currency.
@@ -11,13 +12,14 @@ type Account struct {
model.PermissionBound `bson:",inline" json:",inline"`
model.Describable `bson:",inline" json:",inline"`
AccountCode string `bson:"accountCode" json:"accountCode"` // e.g., "asset:cash:usd"
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
AccountType AccountType `bson:"accountType" json:"accountType"` // asset, liability, revenue, expense
Status AccountStatus `bson:"status" json:"status"` // active, frozen, closed
AllowNegative bool `bson:"allowNegative" json:"allowNegative"` // debit policy: allow negative balances
IsSettlement bool `bson:"isSettlement,omitempty" json:"isSettlement,omitempty"` // marks org-level default contra account
Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
AccountCode string `bson:"accountCode" json:"accountCode"` // e.g., "asset:cash:usd"
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
AccountType AccountType `bson:"accountType" json:"accountType"` // asset, liability, revenue, expense
Status AccountStatus `bson:"status" json:"status"` // active, frozen, closed
AllowNegative bool `bson:"allowNegative" json:"allowNegative"` // debit policy: allow negative balances
IsSettlement bool `bson:"isSettlement,omitempty" json:"isSettlement,omitempty"` // marks org-level default contra account
OwnerRef *primitive.ObjectID `bson:"ownerRef,omitempty" json:"ownerRef,omitempty"` // reference to the owner (e.g., user or entity)
Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
}
// Collection implements storable.Storable.