feat: CDI % configurável por conta + fix mocks de teste
- Adiciona campo cdi_percentage (default 100%) na tabela accounts - Cálculo CDI aplica proporção: balance × (compound-1) × (pct/100) - Frontend exibe input de % quando yield_type=cdi e badge mostra valor - Corrige mocks de teste desatualizados (DeleteByMonth, isTax) - Corrige ConfirmIncome para rejeitar tipo expense (ErrRecurringNotIncome) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -33,13 +33,13 @@ func (m *mockCategoryRepo) GetByID(_ context.Context, id int) (*model.Category,
|
||||
return nil, repository.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *mockCategoryRepo) Create(_ context.Context, name, color string) (*model.Category, error) {
|
||||
func (m *mockCategoryRepo) Create(_ context.Context, name, color string, _ bool) (*model.Category, error) {
|
||||
c := model.Category{ID: len(m.categories) + 1, Name: name, Color: color}
|
||||
m.categories = append(m.categories, c)
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (m *mockCategoryRepo) Update(_ context.Context, id int, name, color string) (*model.Category, error) {
|
||||
func (m *mockCategoryRepo) Update(_ context.Context, id int, name, color string, _ bool) (*model.Category, error) {
|
||||
for i, c := range m.categories {
|
||||
if c.ID == id {
|
||||
m.categories[i].Name = name
|
||||
|
||||
@@ -78,7 +78,11 @@ func (s *CDIYieldService) ApplyYield(ctx context.Context, a *model.Account) erro
|
||||
compound *= 1 + lastRate/100
|
||||
}
|
||||
|
||||
yieldAmount := a.Balance * (compound - 1)
|
||||
cdiPct := a.CDIPercentage
|
||||
if cdiPct <= 0 {
|
||||
cdiPct = 100
|
||||
}
|
||||
yieldAmount := a.Balance * (compound - 1) * (cdiPct / 100)
|
||||
if yieldAmount <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,16 +110,16 @@ func (s *RecurringService) MonthlyStatus(ctx context.Context, month string) ([]m
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ConfirmIncome creates a transaction (income or expense) confirming this recurring item for the month.
|
||||
// ConfirmIncome creates a transaction confirming an income recurring item for the month.
|
||||
func (s *RecurringService) ConfirmIncome(ctx context.Context, id int, month string) error {
|
||||
re, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
txType := re.Type
|
||||
if txType == "" {
|
||||
txType = "expense"
|
||||
if re.Type != "income" {
|
||||
return ErrRecurringNotIncome
|
||||
}
|
||||
txType := re.Type
|
||||
today := time.Now().Format("2006-01-02")
|
||||
tx := model.Transaction{
|
||||
Date: today,
|
||||
|
||||
@@ -89,7 +89,8 @@ func (m *mockTxRepo) Create(_ context.Context, t model.Transaction) (*model.Tran
|
||||
func (m *mockTxRepo) Update(_ context.Context, t model.Transaction) (*model.Transaction, error) {
|
||||
return &t, nil
|
||||
}
|
||||
func (m *mockTxRepo) Delete(_ context.Context, _ int) error { return nil }
|
||||
func (m *mockTxRepo) Delete(_ context.Context, _ int) error { return nil }
|
||||
func (m *mockTxRepo) DeleteByMonth(_ context.Context, _ string) (int, error) { return 0, nil }
|
||||
func (m *mockTxRepo) HasMatchingTransaction(_ context.Context, _ *int, _ string, _ float64, _ string) (bool, error) {
|
||||
return m.matchResult, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user