Repository navigation
Mark invoices as paid #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lodewiges
wants to merge
11
commits into
staging
Choose a base branch
from
claude/project-thread-8nu3bq
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+256
−22
Open
Mark invoices as paid #1306
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f93ec29
Add ability to mark an invoice as paid (#1031)
claude a305dd3
Cover already-paid case for mark_as_paid
claude 2670a99
Create credit mutation when marking invoice as paid
claude 5304f90
Split mark_as_paid spec examples for rubocop
claude 91e39cc
Add booking number to invoices and booked status
claude 581a067
Lock invoice when marking as paid and handle credit validation errors
claude d445f1e
Fix lint offenses and move booking validation into the model
claude ed11b6d
Silence rubocop metrics on new invoice actions
claude d1b4e33
Allow deleting pending invoices
claude 7026b9b
Use described_class in invoice spec
claude 6335c5c
Move invoice actions from the list to the invoice page
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddBookingNumberToInvoices < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :invoices, :booking_number, :string | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe InvoicesController do | ||
| describe 'PATCH book' do | ||
| let!(:invoice) { create(:invoice, status: 'paid') } | ||
|
|
||
| it 'stores the booking number and sets the status to booked' do | ||
| sign_in create(:user, :treasurer) | ||
| patch :book, params: { id: invoice.id, invoice: { booking_number: ' 2026-123 ' } } | ||
|
|
||
| expect(invoice.reload).to have_attributes(booking_number: '2026-123', status: 'booked') | ||
| end | ||
|
|
||
| it 'does not book without a booking number' do | ||
| sign_in create(:user, :treasurer) | ||
| patch :book, params: { id: invoice.id, invoice: { booking_number: ' ' } } | ||
|
|
||
| expect(invoice.reload.status).to eq 'paid' | ||
| end | ||
|
|
||
| it 'does not book an unpaid invoice' do | ||
| unpaid = create(:invoice) | ||
| sign_in create(:user, :treasurer) | ||
| patch :book, params: { id: unpaid.id, invoice: { booking_number: '1' } } | ||
|
|
||
| expect(unpaid.reload.status).to eq 'pending' | ||
| end | ||
|
|
||
| it 'is forbidden for a normal user' do | ||
| sign_in create(:user) | ||
| patch :book, params: { id: invoice.id, invoice: { booking_number: '1' } } | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe InvoicesController do | ||
| describe 'DELETE destroy' do | ||
| let!(:invoice) { create(:invoice) } | ||
|
|
||
| it 'deletes a pending invoice' do | ||
| sign_in create(:user, :treasurer) | ||
|
|
||
| expect { delete :destroy, params: { id: invoice.id } }.to change(Invoice, :count).by(-1) | ||
| expect(response).to redirect_to(invoices_path) | ||
| end | ||
|
|
||
| it 'does not delete a sent invoice' do | ||
| invoice.update!(status: 'sent') | ||
| sign_in create(:user, :treasurer) | ||
|
|
||
| expect { delete :destroy, params: { id: invoice.id } }.not_to change(Invoice, :count) | ||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it 'does not delete a paid invoice' do | ||
| invoice.update!(status: 'paid') | ||
| sign_in create(:user, :treasurer) | ||
|
|
||
| expect { delete :destroy, params: { id: invoice.id } }.not_to change(Invoice, :count) | ||
| end | ||
|
|
||
| it 'is forbidden for a normal user' do | ||
| sign_in create(:user) | ||
|
|
||
| expect { delete :destroy, params: { id: invoice.id } }.not_to change(Invoice, :count) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe InvoicesController do | ||
| describe 'POST mark_as_paid' do | ||
| let!(:invoice) { create(:invoice).tap { |i| create(:invoice_row, invoice: i, amount: 2, price: 20) } } | ||
|
|
||
| let(:treasurer) { create(:user, :treasurer) } | ||
|
|
||
| before { sign_in treasurer } | ||
|
|
||
| it 'marks the invoice as paid' do | ||
| post :mark_as_paid, params: { id: invoice.id } | ||
|
|
||
| expect(invoice.reload.status).to eq 'paid' | ||
| expect(response).to redirect_to(invoice_path(invoice)) | ||
| end | ||
|
|
||
| it 'creates a credit mutation for the invoice user' do | ||
| expect { post :mark_as_paid, params: { id: invoice.id } }.to change(CreditMutation, :count).by(1) | ||
| expect(CreditMutation.last).to have_attributes(user: invoice.user, amount: 40, created_by: treasurer) | ||
| end | ||
|
|
||
| it 'does not change an invoice that is already paid' do | ||
| invoice.update!(status: 'paid') | ||
|
|
||
| expect { post :mark_as_paid, params: { id: invoice.id } }.not_to change(CreditMutation, :count) | ||
|
|
||
| expect(flash[:error]).to eq 'Factuur is al betaald' | ||
| expect(response).to redirect_to(invoice_path(invoice)) | ||
| end | ||
|
|
||
| it 'shows an error instead of crashing when the amount exceeds the credit mutation limit' do | ||
| create(:invoice_row, invoice:, amount: 1, price: 6000) | ||
| patch_count = -> { CreditMutation.count } | ||
|
|
||
| expect { post :mark_as_paid, params: { id: invoice.id } }.not_to change(patch_count, :call) | ||
| expect(invoice.reload.status).to eq 'pending' | ||
| expect(flash[:error]).to be_present | ||
| end | ||
|
|
||
| it 'is forbidden for a normal user' do | ||
| sign_in create(:user) | ||
|
|
||
| expect { post :mark_as_paid, params: { id: invoice.id } }.not_to change(CreditMutation, :count) | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| expect(invoice.reload.status).to eq 'pending' | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support invoice totals above the credit-mutation limit.
A valid invoice can contain one row with quantity
1and price5001;InvoiceRowdoes not cap that total. (raw.githubusercontent.com)For that invoice,
CreditMutation.create!violates theamount <= 5000validation. The transaction rolls back, and the exception escapes the controller. The invoice remains unpaid, and each retry fails again. (raw.githubusercontent.com)Support the full invoice amount while preserving the mutation limit, for example with bounded mutations in the same transaction. Set
paidonly after the full credit succeeds. Return a controlled error response for validation failures.