Skip to content

Commit

Permalink
remove invoice create restrictions & set paid number if created as paid
Browse files Browse the repository at this point in the history
  • Loading branch information
coddmeistr committed Dec 22, 2024
1 parent 47796ea commit 9511a19
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/billing/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,6 @@ func (s *BillingServiceServer) CreateInvoice(ctx context.Context, req *connect.R
return nil, status.Error(codes.PermissionDenied, "Not enough Access Rights")
}

if t.GetStatus() != pb.BillingStatus_DRAFT && t.GetStatus() != pb.BillingStatus_UNPAID {
return nil, status.Error(codes.InvalidArgument, "Status can be only DRAFT and UNPAID on creation")
}
if t.GetTotal() < 0 {
return nil, status.Error(codes.InvalidArgument, "Negative total")
}
if t.Account == "" {
return nil, status.Error(codes.InvalidArgument, "Missing account")
}
Expand Down Expand Up @@ -406,10 +400,22 @@ func (s *BillingServiceServer) CreateInvoice(ctx context.Context, req *connect.R

now := time.Now()

strNum, num, err := s.GetNewNumber(log, unpaidInvoicesByCreatedDate, now, invConf.NewTemplate, "NONE")
if err != nil {
log.Error("Failed to get new number for invoice", zap.Error(err))
return nil, status.Error(codes.Internal, "Failed to get new number for invoice. "+err.Error())
var (
strNum string
num int
)
if t.Status == pb.BillingStatus_PAID {
strNum, num, err = s.GetNewNumber(log, invoicesByPaymentDate, time.Now(), invConf.Template, invConf.ResetCounterMode)
if err != nil {
log.Error("Failed to get next paid number", zap.Error(err))
return nil, status.Error(codes.Internal, "Failed to get next number")
}
} else {
strNum, num, err = s.GetNewNumber(log, unpaidInvoicesByCreatedDate, now, invConf.NewTemplate, "NONE")
if err != nil {
log.Error("Failed to get new number for invoice", zap.Error(err))
return nil, status.Error(codes.Internal, "Failed to get new number for invoice. "+err.Error())
}
}

acc, err := s.accounts.GetAccountOrOwnerAccountIfPresent(ctx, t.Account)
Expand Down

0 comments on commit 9511a19

Please sign in to comment.